How do I authorize a gdata client without using the gdata oauth2 workflow?

后端 未结 3 852
抹茶落季
抹茶落季 2021-01-03 09:26

I already have an access_token and refresh_token, but I can\'t figure out a way to create an authorized gdata client without going through the entire token generation workfl

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 10:02

    Try this:

    import httplib2
    from oauth2client.client import OAuth2Credentials
    
    credentials = OAuth2Credentials('access_token', client_id, client_secret, 'refresh_token', 'token_expiry','token_uri','user_agent')
    # the client_id and client_secret are the ones that you receive which registering the App 
    # and the token_uri is the Redirect url you register with Google for handling the oauth redirection
    # the token_expiry and the user_agent is the one that you receive when exchange the code for access_token
    http = httplib2.Http()
    http = credentials.authorize(http)
    service = build('analytics', 'v3', http=http) # this will give you the service object which you can use for firing API calls
    

提交回复
热议问题