我想获取联系人中所有群组的列表。我使用那段代码:
import gdata.gauth
import gdata.contacts.client
token = gdata.gauth.OAuth2Token(client_id = "***.apps.googleusercontent.com",
client_secret = "***",
scope = "https://www.google.com/m8/feeds/",
user_agent = "GC")
gd_client = gdata.contacts.client.ContactsClient(source = 'GCv0.1')
gd_client = token.authorize(gd_client)
gd_client.GetGroups()
但得到了错误:
Traceback (most recent call last):
File "F:/Yandex/Sites/GoogleContacts/cli_contacts.py", line 27, in <module>
gd_client.GetGroups()
File "C:\Users\Ishayahu\27Gdata\lib\site-packages\gdata\contacts\client.py", line 218, in get_groups
return self.get_feed(uri, desired_class=desired_class, auth_token=auth_token, **kwargs)
File "C:\Users\Ishayahu\27Gdata\lib\site-packages\gdata\client.py", line 640, in get_feed
**kwargs)
File "C:\Users\Ishayahu\27Gdata\lib\site-packages\gdata\client.py", line 319, in request
RequestError)
gdata.client.RequestError: Server responded with: 400,
enter code here
我不知道是什么原因,我找不到任何解决方法。
UPD :看起来我应该以某种方式将acess_token或refresh_token放入OAuth2Token,但我无法理解 所以它发送标题
{'GData-Version': '3', 'Authorization': 'Bearer None', 'User-Agent': 'gdata-py/2.0.17'}
UPD2 :顺便说一句,如果我在OAuth2Playground中测试,它会显示一个页面,其中包含对我的联系人的请求访问权限。该脚本不要求它。也许那就是问题?我该怎么改变它?我想,它与url_redirect连接,但我无法理解,如何使用它
UPD3 :我是对的:如果我添加了access_token,我从Playground手工制作,一切正常。但我应该如何在脚本中获取它?!