2012-07-24 114 views
0

我们想从google API导入联系人照片。Google联系人。 GetPhoto

以下代码正在为我工​​作。

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 feed copy。所以方法GetPhoto无法正常工作。

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

回答

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) #