2012-06-07 58 views
1

我嘗試檢索與gdata.contacts.client聯繫人:獲取與蟒蛇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之間有沒有

PS:feed_groups = gd_client.GetGroup(group_url)的作品就像一個魅力...

PS:Source file源文件中的函數ModifyMe

回答

1

我想你使用的是錯誤的URL,正確的如下所示:

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

哪裏<email>是你所要求的,接觸的用戶的電子郵件地址(當然,你必須經過授權才能訪問這些聯繫人)。該字段還可以採用值「default」來替換當前通過身份驗證的用戶的電子郵件地址。

contactId是由API返回的聯繫人的標識符。我認爲你有這個權利。

此外,還要確保該協議是https,而不是http

+0

如果我嘗試使用URL https:// www.google.com/m8/feeds/contacts/yohann @ mail.info/base/2e091c5e8b3d61b4',我也會得到http 400.其中'[email protected] '是用戶的電子郵件(谷歌應用程序帳戶)。我通過列出組「entry.id.text」的用戶來獲取此URL。 – Yohann

+0

嘗試發送使用OAuth 2.0遊樂場(https://code.google.com/oauthplayground/)相同的請求,400響應代碼還應該包括更詳細的錯誤信息,告訴什麼地方錯了你的要求。 –

+0

它與'的https:// www.google.com/M8 /供稿/聯繫人/ yohann%40lepage.info /基/ 2e091c5e8b3d60b4' .. – Yohann