问题
I try to retrieve a contact with gdata.contacts.client
:
Auth :
class ModifyMe(webapp.RequestHandler):
@login_required
def get(self):
"""print contacts"""
current_user = users.get_current_user()
access_token_key = 'access_token_%s' % current_user.user_id()
token = gdata.gauth.ae_load(access_token_key)
gcontacts_client = gdata.contacts.client.ContactsClient(source = SETTINGS['APP_NAME'])
gcontacts_client = token.authorize(gcontacts_client)
According to API documentation, i tried this :
contact = gcontacts_client.GetContact('https://www.google.com/m8/feeds/contacts/yohann%40mail.info/base/2e091c5e9b3d60b4')
But i had this error :
Traceback (most recent call last):
File "/base/data/home/apps/s~yoyocontacts/2.359462823193148133/main.py", line 246, in PrintContact
contact = gd_client.GetContacts('https://www.google.com/m8/feeds/contacts/yohann%mail.info/base/2e091c5e9b3d60b4')
File "/base/data/home/apps/s~yoyocontacts/2.359462823193148133/gdata/contacts/client.py", line 201, in get_contacts
desired_class=desired_class, **kwargs)
File "/base/data/home/apps/s~yoyocontacts/2.359462823193148133/gdata/client.py", line 640, in get_feed
**kwargs)
File "/base/data/home/apps/s~yoyocontacts/2.359462823193148133/gdata/client.py", line 319, in request
RequestError)
RequestError: Server responded with: 400,
Ok, try again :
contact = gcontacts_client.GetContact('www.google.com/m8/feeds/contacts/yohann%40mail.info/base/2e091c5e9b3d60b4')
An other error :
Traceback (most recent call last):
File "/base/data/home/apps/s~yoyocontacts/2.359462880270555204/main.py", line 246, in PrintContact
contact = gd_client.GetContact('www.google.com/m8/feeds/contacts/yohann%40lepage.info/base/2e091c5e8b3760b4')
File "/base/data/home/apps/s~yoyocontacts/2.359462880270555204/gdata/contacts/client.py", line 89, in get_contact
desired_class=desired_class, **kwargs)
File "/base/data/home/apps/s~yoyocontacts/2.359462880270555204/gdata/client.py", line 652, in get_entry
desired_class=desired_class, **kwargs)
File "/base/data/home/apps/s~yoyocontacts/2.359462880270555204/gdata/client.py", line 267, in request
uri=uri, auth_token=auth_token, http_request=http_request, **kwargs)
File "/base/data/home/apps/s~yoyocontacts/2.359462880270555204/atom/client.py", line 119, in request
http_request.method, str(http_request.uri)))
MissingHost: No host provided in request GET https://Nonewww.google.com/m8/feeds/contacts/yohann%40mail.info/base/2e091c5e8b3760b4
Oh wait ! https:// None www.google.com/m8/feeds/contacts/yohann%40mail.info/base/2e091c5e8b3760b4
How fix this behavior ? Why there is None between https:// and uri ?
PS : feed_groups = gd_client.GetGroup(group_url)
works like a charm...
PS : Source fileSource file function ModifyMe
回答1:
I think you are using the wrong url, the correct one looks like the following:
https://www.google.com/m8/feeds/contacts/<email>/base/<contactId>
Where <email>
is the email address of the user you are requesting the contact for (obviously, you must be authorized to access those contacts). This field can also assume the value "default" to replace the email address of the currently authenticated user.
contactId
is the identifier of the contact as returned by the API. I think you got this right.
Also, make sure the protocol is https
and not http
.
来源:https://stackoverflow.com/questions/10940187/retrieve-one-contact-with-python-gdata-contacts-client