0

GoogleAPIから連絡先の写真をインポートしたいと思います。

次のコードは私のために働いていました。

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)

さて、いくつかの理由で、ファイルにアトムフィードコピーを取得します。したがって、メソッドGetPhotoは機能しません。

アイデア、それが起こった理由、連絡先の写真を取得する現在の方法は何ですか?

4

1 に答える 1

1

GoogleAPIの変更を回避する方法は次のとおりです。現在、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 に答える