2012-09-24 48 views
1

我試圖更新使用YouTube API的入口被調用。這是我的錯誤我與掙扎:蟒蛇類型錯誤:不受約束的方法UpdateVideoEntry()必須與YouTubeService例如

Traceback (most recent call last): File "", line 1, in updated_entry = gdata.youtube.service.YouTubeService.UpdateVideoEntry(YTVentry.id) TypeError: unbound method UpdateVideoEntry() must be called with YouTubeService instance as first argument (got NoneType instance instead)

這裏是我的代碼:

import gdata.youtube 
    import gdata.youtube.service 
    import gdata.youtube.data 
client = gdata.youtube.service.YouTubeService()  
... 
videos_feed = client.GetYouTubeVideoFeed(uri) 
    for entry in videos_feed.entry: 
    print entry.title.text 
     YTentry = entry._GDataEntry__GetId 
     YTVentry = gdata.youtube.YouTubeVideoEntry(YTentry) 
     YTVentry.media.title = '09.11.2012 Hold me close' 
     YTVentry.media.description = '09.11.2012 : Hold me close section' 
     updated_entry = gdata.youtube.service.YouTubeService.UpdateVideoEntry(YTVentry.id) 

按照谷歌的YouTube GDATA文檔:

To update video meta-data, simply update the YouTubeVideoEntry object and then use the YouTubeService objects' UpdateVideoEntry method. This method takes as a parameter a YouTubeVideoEntry that contains updated meta-data.

在此先感謝。

回答

1
updated_entry = gdata.youtube.service.YouTubeService.UpdateVideoEntry(YTVentry.id) 

應該

updated_entry = client.UpdateVideoEntry(YTVentry.id) 

gdata.youtube.service.YouTubeService.UpdateVideoEntry(YTVentry.id) TypeError: unbound method UpdateVideoEntry() must be called with YouTubeService instance as first argument (got NoneType instance instead)

的錯誤是抱怨,因爲你正試圖從類調用UpdateVideoEntry而不是你所創建的客戶對象。您已創建YouTubeService對象client,您需要使用該對象,而不是直接調用類的方法。

1

你呼籲YouTubeService類中的方法,而不是在這個類的一個實例。換句話說,你應該叫client.UpdateVideoEntry(...),而不是作爲YouTubeService.UpdateVideoEntry(...)與其他對API的調用。

的文檔,甚至說,你應該叫YouTubeService對象的方法,而不是通過類。

錯誤消息指示您可以可以直接調用類方法,但必須傳遞該類的實例作爲第一個參數。當您在實例上調用方法時,這是隱式完成的,但在調用類上的方法時必須顯式完成。否則,Python將不知道該方法應該在哪個實例上運行(即,什麼是self)。

相關問題