谷歌联系人。 GetPhoto

时间:2012-07-24 14:41:36

标签: python google-api gdata

我们要从Google API导入联系人照片。

以下代码对我有用。

for email, name, entry in feed:
    photo = client.GetPhoto(entry)
    if photo:
        fname = str(uuid.uuid4()) + '.jpg'
        image_file = open(dname + '/' + fname, 'wb')
        image_file.write(photo)
        image_file.close()
        result[email] = '/media/import/%s/%s' % (dir, fname)

现在,由于某些原因,我们进入文件原子Feed副本。所以方法GetPhoto没有用。

任何想法,为什么会发生以及检索联系人照片的当前方式是什么?

1 个答案:

答案 0 :(得分:1)

以下是谷歌API更改的工作。现在我们正在使用对API的直接请求。

for email, name, entry in feed:
    photo_link = e.GetPhotoLink()
    if photo_link:
        request = http.request(
            'GET',
            photo_link.href,
            headers={
                'Authorization':'OAuth %s' % client.current_token.access_token
            }
        )

        if request.status == 200:
            photo = str(request.read())
            fname = str(uuid.uuid4()) + '.jpg'
            image_file = open(dname + '/' + fname, 'wb')
            image_file.write(photo)
            image_file.close()
            result[email] = '/media/import/%s/%s' % (tid, fname) #str(photo.href) #
相关问题