使用python gdata GetContacts()的意外关键字'auth_token'

时间:2015-11-09 22:07:23

标签: python gdata google-contacts

运行以下代码时,为什么会出现以下所示的关键字错误?它在最后一行失败了:feed = gc.GetContacts()

代码

from oauth2client.client import OAuth2Credentials
import gdata.contacts.client

authfn = '/home/ms/gcontactsback.oauth'
f = open(authfn, "r")
credentials = OAuth2Credentials.from_json(f.read())
f.close()

gc = gdata.contacts.client.ContactsClient(source='gback')
gc = credentials.authorize(gc)
feed = gc.GetContacts()

输出

(py)ms@ny:~/py$ ./gcontacts.py

Traceback (most recent call last):
  File "./gcontacts.py", line 19, in <module>
    feed = gc.GetContacts()
  File "/home/ms/py/local/lib/python2.7/site-
      packages/gdata/contacts/client.py", line 201, in get_contacts
  desired_class=desired_class, **kwargs)
  File "/home/ms/py/local/lib/python2.7/site-packages/gdata/client.py",
   line 640, in get_feed
   **kwargs)
  File "/home/ms/py/local/lib/python2.7/site-
    packages/oauth2client/util.py", line 137, in positional_wrapper
  return wrapped(*args, **kwargs)
TypeError: new_request() got an unexpected keyword argument 'auth_token'

(py)ms@ny:~/py$ 

1 个答案:

答案 0 :(得分:0)

我这样做了:

gc = gdata.contacts.client.ContactsClient(source='gback')
auth2token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
gc = auth2token.authorize(gc)
feed = gc.GetContacts()