0

我们想从谷歌 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)

现在,由于某些原因,我们获得了文件 atom 提要副本。所以方法GetPhoto不起作用。

有什么想法,为什么会发生,目前检索联系人照片的方法是什么?

4

1 回答 1

1

这是解决 google 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) #
于 2012-07-25T12:13:05.557 回答