从 Google 的联系人 API 检索联系人的照片
我只是将 google 文档粘贴到此处:
检索联系人的照片
要检索联系人的照片,请向该联系人的照片链接发送 HTTP GET 请求。服务器返回照片的字节。例如,要获取具有某个元素的联系人照片的最新版本:
<link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*'
href='https://google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de'
gd:etag='"KTlcZWs1bCp7ImBBPV43VUV4LXEZCXERZAc."'/>
发送以下 HTTP 请求:
GET https://google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de
这样我就得到了图像的“字节”。我该怎么办呢。我真的不想保存这个,我只想显示个人资料图片。
但看起来我必须将其写入文件然后上传?所以谷歌太过分了。为什么不直接链接到图片...啊!
我正在使用 Rails 3,我尝试将二进制文件写入文件,然后用回形针上传,但我不知道文件类型,所以我应该从哪里获取它?
这就是我编写文件的方式:
tempfile = Tempfile.new('w')
File.open(tempfile.path,'wb') do |f|
f.write photo.body
end
然后附加文件并创建一个新对象。我知道我会做错事。最好的方法是什么?
I'm just pasting the google doc here:
Retrieving a photo for a contact
To retrieve a photo for a contact, send an HTTP GET request to the photo link of this contact. The server returns bytes of the photo. For example, to get the latest version of a photo for a contact with an element:
<link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*'
href='https://google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de'
gd:etag='"KTlcZWs1bCp7ImBBPV43VUV4LXEZCXERZAc."'/>
Send the following HTTP request:
GET https://google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de
So I got this going and I'm getting the 'bytes' of the image. What am I'm supposed to do with this. I really don't want to save this, all I want to do is display the profile picture.
But it looks like I'm going to have to write this to a file and then upload it? So overkil Google. Why not just link to a picture... ah!
I'm using Rails 3 and I've tried writing the binary to a file and then uploading it with paperclip but I don't know the file type so where am I supposed to get that?
This is how I'm writing the file:
tempfile = Tempfile.new('w')
File.open(tempfile.path,'wb') do |f|
f.write photo.body
end
And then I attach the file and create a new object. I know I'm going about this wrong. What's the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,并且一直在谷歌搜索,谷歌不支持“链接照片”,他们只向您发送字节
https://developers.google.com/google-apps/contacts/v3/?hl=es#retriving_a_contacts_photo
As long as I know, and have been googling, Google doesnt support "link photos", they send you just the bytes
https://developers.google.com/google-apps/contacts/v3/?hl=es#retrieving_a_contacts_photo