2

YouTubeビデオがプライベートとして設定されていて、gdata Python APIを使用してそれをフェッチしようとすると、そのビデオを所有するアカウントでプログラムによるログインを行ったにもかかわらず、404RequestError発生します。

from gdata.youtube import service
yt_service = service.YouTubeService(email=my_email,
                                    password=my_password,
                                    client_id=my_client_id,
                                    source=my_source,
                                    developer_key=my_developer_key)
yt_service.ProgrammaticLogin()
yt_service.GetYouTubeVideoEntry(video_id='IcVqemzfyYs')
---------------------------------------------------------------------------
RequestError                              Traceback (most recent call last)

<ipython console> 

/usr/lib/python2.4/site-packages/gdata/youtube/service.pyc in GetYouTubeVideoEntry(self, uri, video_id)
    203     elif video_id and not uri:
    204       uri = '%s/%s' % (YOUTUBE_VIDEO_URI, video_id)
--> 205     return self.Get(uri, converter=gdata.youtube.YouTubeVideoEntryFromString)
    206 
    207   def GetYouTubeContactFeed(self, uri=None, username='default'):

/usr/lib/python2.4/site-packages/gdata/service.pyc in Get(self, uri, extra_headers, redirects_remaining, encoding, converter)
   1100             'body': result_body}
   1101     else:
-> 1102       raise RequestError, {'status': server_response.status,
   1103           'reason': server_response.reason, 'body': result_body}
   1104 

RequestError: {'status': 404, 'body': 'Video not found', 'reason': 'Not Found'}

これは、YouTubeアカウントに(YouTube Webサイトから)アクセスして公開しない限り、毎回発生します。その後、Python APIを使用して、非公開として設定し、公開に戻すことができます。

ステップがありませんか、それともAPIからプライベートとしてYouTubeビデオセットをフェッチする別の(または任意の)方法がありますか?

前もって感謝します。

4

1 に答える 1

0

どうやらYouTubeDataAPIはこれを(まだ)許可していないので、これを回避するには、 YouTubeServiceインスタンスのGetYouTubeUserFeedメソッドを使用して、必要なすべてのビデオエントリのリストを取得します(プライベートかパブリックかに関係なく)。

from gdata.youtube import service
VIDEO_ID = 'IcVqemzfyYs'
yt_service = service.YouTubeService(email=my_email,
                                password=my_password,
                                client_id=my_client_id,
                                source=my_source,
                                developer_key=my_developer_key)
yt_service.ProgrammaticLogin()
userfeed = yt_service.GetYouTubeUserFeed(username=my_email[:my_email.index('@')])
video_entry = reduce(lambda e1, e2: e1 if e1.id.text.endswith(VIDEO_ENTRY) else (e2 if e2.id.text.endswith(VIDEO_ENTRY) else None),
                     userfeed.entry)

これが同じ問題を抱えている人に役立つことを願っています:)

于 2010-06-08T12:30:35.350 に答える