【问题标题】:Authenticate with Google Python SDK with only auth_token or the refresh_token仅使用 auth_token 或 refresh_token 使用 Google Python SDK 进行身份验证
【发布时间】:2015-03-23 18:28:48
【问题描述】:

我有一堆 gmail.storage 文件,其中包含一个 JSON blob,其中包含用户帐户的访问信息。我使用 PHP 获得了这些凭据集,以提示用户对我的应用进行身份验证/授权。我可以使用这些凭据调用 Gmail API。 JSON 具有以下字段:

{"access_token": xxxxxx,
"token_type":"Bearer",
"expires_in":3599,
"refresh_token":"xxxxxx",
"created":1421545394}

但是,当我使用 Python SDK for Gmail 使用这些凭据文件对呼叫进行身份验证时,如下所示:

 credentials = storage.get()

它说它需要_module_class 和其他一些字段。当我使用 Python 获取信息而不是使用 PHP 时,我能够获得这些信息。知道如何在没有这些无关字段的情况下使用上述代码获取凭据吗?

【问题讨论】:

    标签: python authentication oauth-2.0 google-api google-oauth


    【解决方案1】:

    在再次使用凭据之前调用刷新方法。

    storage = file.Storage("auth.dat")
    credentials = storage.get()
    
    http = httplib2.Http()
    credentials.refresh(http)   # <----------
    http = credentials.authorize(http)
    
    service = build('whatever_service', 'v2', http=http)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      • 1970-01-01
      • 2016-02-03
      • 2016-05-31
      • 2017-03-11
      • 2018-10-19
      • 1970-01-01
      相关资源
      最近更新 更多