Google API: getting Credentials from refresh token with oauth2client.client

前端 未结 10 1887
失恋的感觉
失恋的感觉 2020-11-29 05:06

I am using googles official oauth2client.client to access the google plus api. I have a refresh token (that does not expire) stored in a database, and need to recreate the

10条回答
  •  醉话见心
    2020-11-29 05:32

    I recommend this method.

    from oauth2client import client, GOOGLE_TOKEN_URI
    
    CLIENT_ID = "client_id"
    CLIENT_SECRET = "client_secret"
    REFRESH_TOKEN = "refresh_token"
    
    
    credentials = client.OAuth2Credentials(
        access_token = None, 
        client_id = CLIENT_ID, 
        client_secret = CLIENT_SECRET, 
        refresh_token = REFRESH_TOKEN, 
        token_expiry = None, 
        token_uri = GOOGLE_TOKEN_URI,
        token_ id = None, 
        revoke_uri= None)
    
    http = credentials.authorize(httplib2.Http())
    

    Even if the access token has expired, the credential is still authorize because of the refresh token.

提交回复
热议问题