0

我开发了一个装饰器来验证我的应用程序并开始使用 youtube API。装饰器指定包装一个 REST 资源类的方法。

def youtube_auth(f):                                            
    def wrap(self, *args, **kwargs):                            
        youtube_serv = gdata.youtube.service.YouTubeService()   
        youtube_serv.ssl = True                                 
        youtube_serv.developer_key = YOUTUBE_DEVELOPER_KEY      
        youtube_serv.client_id = YOUTUBE_CLIENT_ID              
        def get_auth_sub_url():                                 
            # TODO: do not forget to change it to real URL      
            next = 'http://www.example.com/video_upload'        
            scope = 'http://gdata.youtube.com'                  
            secure = False                                      
            session = True                                      

            return youtube_serv.GenerateAuthSubURL(next, scope, 
                 secure, session)                            

        # TODO: understand how to check authsub token           
        # if not youtube_serv.is_authenicated():                
        #     return redirect(get_auth_sub_url())               
        # else:                                                 
        #     parameters = cgi.FieldStorage()                   
        #     authsub_token = parameters.get('token')           
        #     yt_service = gdata.youtube.service.YouTubeService(
        #     yt_service.SetAuthSubToken(authsub_token)         
        #     yt_service.UpgradeToSessionToken()                

        return f(self, *args, **kwargs)                         
    return wrap                                                 

如何检查用户是否经过身份验证(令牌是否存在)?

4

1 回答 1

0

由于这是一个新应用程序,您应该考虑使用新的 OAuth 2.0 界面。此处的文档:https ://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2

工作示例(php):Youtube Oauth 2.0 API Videos Upload Failed

于 2012-09-04T20:35:08.577 回答