我正在尝试使用youtube api更新一个条目。以下是我正在努力克服的错误:
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)
根据谷歌gdata youtube文档:
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.
提前谢谢。在
您是在},就像对API的其他调用一样。在
YouTubeService
类上调用该方法,而不是在该类的实例上调用该方法。换句话说,您应该调用client.UpdateVideoEntry(...)
,而不是{文档甚至说应该在
YouTubeService
对象上调用该方法,而不是在类上调用该方法。在错误消息表明您可以直接调用class方法,但必须将类的实例作为第一个参数传递。当您在实例上调用方法时,这是隐式的,但是在类上调用方法时必须显式地完成。否则Python将不知道该方法应该在哪个实例上操作(即,
self
是什么)。在应该是
^{pr2}$错误正在抱怨,因为您尝试从类调用UpdateVideoEntry,而不是从您创建的客户机对象调用。您已经创建了一个YouTubeService对象,
client
,您需要使用它,而不是直接调用类的方法。在相关问题 更多 >
编程相关推荐