2010-12-11 46 views
2

我試圖使用youtube gdata python api將視頻添加到我的播放列表時,無法克服此錯誤。通過youtube api將視頻添加到播放列表時無效的請求URI

gdata.service.RequestError: {'status': 400, 'body': 'Invalid request URI', 'reason': 'Bad Request'}

This似乎是同樣的錯誤,但目前還沒有解決方案。任何幫助傢伙?

import getpass 
import gdata.youtube 
import gdata.youtube.service 

yt_service = gdata.youtube.service.YouTubeService() 

# The YouTube API does not currently support HTTPS/SSL access. 
yt_service.ssl = False 
yt_service = gdata.youtube.service.YouTubeService() 
yt_service.email = #myemail 
yt_service.password = getpass.getpass() 
yt_service.developer_key = #mykey 
yt_service.source = #text 
yt_service.client_id= #text 
yt_service.ProgrammaticLogin() 

feed = yt_service.GetYouTubePlaylistFeed(username='default') 
# iterate through the feed as you would with any other 
for entry in feed.entry: 
    if (entry.title.text == "test"): 
     lst = entry; 
     print entry.title.text, entry.id.text 

custom_video_title = 'my test video on my test playlist' 
custom_video_description = 'this is a test video on my test playlist' 
video_id = 'Ncakifd_16k' 
playlist_uri = lst.id.text  

playlist_video_entry = yt_service.AddPlaylistVideoEntryToPlaylist(playlist_uri, video_id, custom_video_title, custom_video_description)  

if isinstance(playlist_video_entry, gdata.youtube.YouTubePlaylistVideoEntry): 
print 'Video added' 

混淆的是,更新播放列表的作品,但添加視頻不。

playlist_entry_id = lst.id.text.split('/')[-1] 
original_playlist_description = lst.description.text 
updated_playlist = yt_service.UpdatePlaylist(playlist_entry_id,'test',original_playlist_description,playlist_private=False) 

video_id沒有錯,因爲它的視頻來自示例代碼。我在這裏錯過了什麼?有人幫忙!

謝謝。

回答

2

Gdata似乎使用v1 API。因此,相關文檔在這裏:http://code.google.com/apis/youtube/1.0/developers_guide_protocol.html#Retrieving_a_playlist

這意味着,您的「playlist_uri」不應取「lst.id.text」的值,而應採用「feedLink」元素的「href」屬性以便與「AddPlaylistVideoEntryToPlaylist」

即使你碰巧使用V2 API使用,你應該從「內容」元素的「src」屬性採取URI如文檔中說明,您可以通過替換2.0,在上述網址搞定! (SO不允許我放兩個超鏈接,因爲我沒有足夠的聲譽:))

相關問題