使用python-oauth2时出现oauth_parameters_absent:scope

2 投票
1 回答
775 浏览
提问于 2025-04-16 22:17

我在我的项目中尝试使用python-auth2,但遇到了这个错误:

In [1]: import oauth2 as oauth

In [2]: consumer_key='dijscrape.ep.io'

In [3]: consumer_secret='my-secret-here'

In [4]: REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken'

In [5]: consumer = oauth.Consumer(consumer_key, consumer_secret)

In [6]: client = oauth.Client(consumer)

In [7]: r, c = client.request(REQUEST_TOKEN_URL, "GET")

In [8]: print r
------> print(r)
{'status': '400', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'transfer-encoding': 'chunked', 'expires': 'Tue, 26 Jul 2011 13:38:13 GMT', 'server': 'GSE', 'cache-control': 'private, max-age=0', 'date': 'Tue, 26 Jul 2011 13:38:13 GMT', 'content-type': 'text/plain; charset=UTF-8'}

In [9]: print c
------> print(c)
parameter_absent
oauth_parameters_absent:scope

这可能是什么原因呢?

1 个回答

2

谷歌要求在请求令牌的链接中添加一个'scope'参数。

http://code.google.com/apis/accounts/docs/OAuth.html#prepScope

所以需要像这样

scope = "http://www.google.com/calendar/feeds/default/allcalendars/full"
REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken?scope={0}'.format(scope)

我注意到你还没有对你问过的问题接受任何答案。如果有答案对你有帮助,请记得点击答案旁边的勾勾来接受它。

撰写回答