【问题标题】:Retrieve one contact with python gdata.contacts.client使用 python gdata.contacts.client 检索一个联系人
【发布时间】:2012-06-12 00:02:42
【问题描述】:

我尝试检索gdata.contacts.client 的联系人:

授权:

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)

根据 API 文档,我试过这个:

        contact = gcontacts_client.GetContact('https://www.google.com/m8/feeds/contacts/yohann%40mail.info/base/2e091c5e9b3d60b4')

但我有这个错误:

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, 

好的,再试一次:

        contact = gcontacts_client.GetContact('www.google.com/m8/feeds/contacts/yohann%40mail.info/base/2e091c5e9b3d60b4')

另一个错误:

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

哦等等! https:// www.google.com/m8/feeds/contacts/yohann%40mail.info/base/2e091c5e8b3760b4

如何解决这种行为?为什么 https:// 和 uri 之间有 None

PS : feed_groups = gd_client.GetGroup(group_url) 就像一个魅力...

PS:Source file源文件函数ModifyMe

【问题讨论】:

    标签: python google-app-engine google-api gdata google-contacts-api


    【解决方案1】:

    我认为您使用了错误的网址,正确的网址如下所示:

    https://www.google.com/m8/feeds/contacts/<email>/base/<contactId>
    

    其中&lt;email&gt; 是您请求联系的用户的电子邮件地址(显然,您必须有权访问这些联系人)。该字段还可以采用“默认”值来替换当前经过身份验证的用户的电子邮件地址。

    contactId 是 API 返回的联系人标识符。我认为你说得对。

    另外,请确保协议是 https 而不是 http

    【讨论】:

    • 如果我尝试使用 url https://www.google.com/m8/feeds/contacts/yohann@mail.info/base/2e091c5e8b3d61b4,我也会得到 http 400。其中yohann@mail.com 是用户的电子邮件(谷歌应用程序帐户)。我通过列出组entry.id.text 的用户来检索此网址。
    • 尝试使用 OAuth 2.0 Playground (code.google.com/oauthplayground) 发送相同的请求,400 响应代码还应包含更详细的错误消息,说明您的请求有什么问题。
    • 它适用于https://www.google.com/m8/feeds/contacts/yohann%40lepage.info/base/2e091c5e8b3d60b4..
    • @Yohann 我认为这是因为令牌没有永久存储。
    猜你喜欢
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    相关资源
    最近更新 更多