我有一个应用程序使用 Google 联系人 API https://developers.google.com/google-apps/contacts/v3/通过 gdata 访问用户联系人。我正在使用 gdata 库来访问它,并使用 OpenID+OAuth1 来登录并请求授权。谷歌最近做了一些改变,现在声明:
Warning: Due to enhanced security measures we've added to our
infrastructure, all developers using the Contacts API must register their
projects in the API Console <https://code.google.com/apis/console> and
ensure the Contacts API is activated in the API Console.
If your application has certain unusual authorization requirements, such aslogging
in at the same time as requesting data access (hybrid<http://code.google.com/apis/accounts/docs/OpenID.html#oauth>
) or domain-wide delegation of authority (2LO<http://code.google.com/apis/accounts/docs/OAuth.html#GoogleAppsOAuth>
), then you cannot currently use OAuth 2.0 tokens.
In such cases, you must instead use OAuth 1.0 tokens and an API key<http://code.google.com/apis/console-help/#WhatIsKey>
. You can find your application's API key in the GoogleAPI Console<https://code.google.com/apis/console#access>,
in the Simple API Access section of the API Access pane.
您如何在 gdata 请求旁边设置 API 密钥?(假设 oAuth 令牌都已处理)?
我试过了:
query = gdata.contacts.service.ContactsQuery(params={'key':'MY_API_KEY'})
query.max_results = 200
feed = googleintegration.contacts_service.GetContactsFeed(query.ToUri())
但我总是得到一个 401 客户端错误。