【问题标题】:How to use OAuth2Credentials with Google API gdata client in python?如何在 python 中将 OAuth2Credentials 与 Google API gdata 客户端一起使用?
【发布时间】:2012-09-29 08:02:40
【问题描述】:

我已经了解了 OAuth2 的工作原理(通过 https://developers.google.com/api-client-library/python/guide/aaa_oauth),现在有一个 OAuth2Credentials 对象(我们称之为对象 credentials),我想将其用于 Google Apps 配置目的(此处的示例是使用站点,但可以是任何 gdata api)

如果我尝试:

client = gdata.sites.client.SitesClient(site="test-site",domain='my.domain')
client = credentials.authorize(client)

我明白了

TypeError: new_request() got an unexpected keyword argument 'http_request'

当我尝试做任何事情时

如果我尝试

client = gdata.sites.client.SitesClient(site="test-site",domain='my.domain', auth_token=credentials)

client = gdata.sites.client.SitesClient(site="test-site",domain='my.domain', auth_token=credentials.access_token)

我收到一个 AttributeError,表明相关对象(凭据或凭据.access_token)没有属性“modify_request”

有什么我可以尝试的想法吗?

【问题讨论】:

    标签: python oauth-2.0 gdata gdata-api google-data-api


    【解决方案1】:

    我不完全确定 Google 的客户端代码,但您可以随时尝试(无耻插件)sanction。这是我不久前在 Github 和 PyPI 上编写的 OAuth 2.0 客户端。

    优点:

    • 作为一个惊人的 55 LOC,它非常很容易摸索。如果出现问题,您不必在这里提问。您应该能够理解发生了什么;)
    • 已通过 8 家不同的提供商(包括 Google)的测试

    缺点:

    • 显然需要重构您当前的代码
    • 不假设(因此提供)持久性实现
    • 不提供 API 实现(您必须对所处理的 OAuth 2.0 公开 API 有基本的了解)

    【讨论】:

      【解决方案2】:

      answer 表示您必须先对 OAuth2Credentials 对象进行猴子补丁,然后再将其传递给 SitesClient(auth_token=credentials)。它有一个答案告诉你如何做猴子补丁

      【讨论】:

      • 看到了,但看起来很乱,并且没有提供代码。所以我想我会看看是否有正确的方法来做到这一点
      猜你喜欢
      • 2015-06-16
      • 2015-10-11
      • 2012-10-12
      • 2020-06-09
      • 1970-01-01
      • 2011-04-08
      • 2016-10-14
      • 2014-01-14
      • 2017-12-15
      相关资源
      最近更新 更多