【问题标题】:Get error 400 when retrieving anything from Google Contacts using Python gdata API使用 Python gdata API 从 Google 通讯录中检索任何内容时出现错误 400
【发布时间】:2015-05-03 13:58:09
【问题描述】:

刚开始使用 gdata (Python)。令人惊讶的是,在正确设置凭据后,每当我尝试检索所有文件时,我都会得到 HTTP 代码 400。看看这段代码:

s = 'https://www.google.com/m8/feeds'
s = 'https://www.google.com/m8/feeds/contacts/default/full/'

client_secret = CLIENT_SECRET
client_id = CLIENT_ID

client = gdata.contacts.client.ContactsClient()
auth2token = gdata.gauth.OAuth2Token(
        client_id = client_id,
        client_secret = client_secret,
        scope = s,
        user_agent = "bla")
auth2token.authorize(client)

try:
    feed = client.get_contacts()
except gdata.client.RequestError as e:
    print e.args
    print e.body
    print e.headers
    print e.message
    print e.reason
    print e.status

不幸的是,无论s 的值是多少,我总是会出错。查看这段代码的输出:

('Server responded with: 400, ',)

[('alternate-protocol', '443:quic,p=0.08'), ('x-xss-protection', '1; mode=block'), ('x-content-type-options', 'nosniff'), ('transfer-encoding', 'chunked'), ('accept-ranges', 'none'), ('expires', 'Fri, 01 Jan 1990 00:00:00 GMT'), ('vary', 'Accept-Encoding'), ('server', 'GSE'), ('pragma', 'no-cache'), ('cache-control', 'no-cache, no-store, max-age=0, must-revalidate'), ('date', 'Tue, 03 Mar 2015 02:12:08 GMT'), ('x-frame-options', 'SAMEORIGIN'), ('content-type', 'application/json')]
Server responded with: 400, 
Bad Request
400

有什么线索吗?

谢谢!

【问题讨论】:

  • 这个答案可能会有所帮助:stackoverflow.com/questions/10188768/…
  • 感谢您的链接。似乎这些解决方案(使用 OAuth2),至少我在 Web 中看到的示例,仅适用于 Web 应用程序,而不是在计算机中运行的独立应用程序。我可以使用普通用户/密码登录检索联系人信息:-/。谢谢。

标签: python rest oauth gdata google-contacts-api


【解决方案1】:

我怀疑问题可能出在重新身份验证中,即这个流程:

  1. 您允许您的应用访问
  2. 也许你没有保存令牌
  3. 如果您这次再次允许已允许的应用程序访问,则保存令牌。

使用 (3) 中的标记的标记给我一个 400 错误。但是,如果我:

  1. 转到我的 Google 帐户并取消我的本地应用程序和我的联系人之间的关联
  2. 在本地删除所有令牌,然后重新验证它似乎工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 2012-08-02
    • 1970-01-01
    相关资源
    最近更新 更多