如何将照片添加到谷歌联系人?

时间:2018-06-08 02:04:38

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

我正在尝试使用python和gdata库将照片添加到Google联系人。

contact = gd_client.GetContact('http://www.google.com/m8/feeds/contacts/denisz.pol%40gmail.com/base/61839cbb8a335dbb')
gd_client.ChangePhoto('img.jpeg',contact)

但是有一个错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-62-03d065010e8f> in <module>()
----> 1 gd_client.ChangePhoto('img.jpeg',contact)

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gdata/contacts/client.py in change_photo(self, media, contact_entry_or_url, content_type, content_length, auth_token, **kwargs)
    253         ifmatch_header = None
    254         if isinstance(contact_entry_or_url, gdata.contacts.data.ContactEntry):
--> 255             photo_link = contact_entry_or_url.GetPhotoLink()
    256             uri = photo_link.href
    257             ifmatch_header = atom.client.CustomHeaders(

AttributeError: 'NoneType' object has no attribute 'href'

如果我添加照片以“手动”联系,则不会有任何改变。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

很奇怪,但如果我们在GetPhotLink()函数ChangePhoto属性之外调用href,则不会None。所以这段代码

gd_client.ChangePhoto('img.jpeg',contact.GetPhotoLink().href, content_type='image/*')

会更改照片。

相关问题