AuthSub. How to check token existence? Python gdata client

257 views Asked by At

I develop a decorator to authenticate my app and start to work with youtube API. Decorator appointed to wrap a REST resource class methods.

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                                                 

How do I check the whether a user is authenticated (whether the token exists)?

1

There are 1 answers

0
Carl On

Since this is a new app, you should look into using the new OAuth 2.0 interface. Documentation here: https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2

working example (php) here: Youtube Oauth 2.0 API Videos Upload Failed