我知道许多社交网络APIs提供了一种方法,可以使用用户的user_id或用户名来构建指向用户头像的url。对于Facebook,它看起来是这样的:
http://graph.facebook.com/user_id/picture?type=square
现在Google Plus有没有类似的东西?或者其他不需要API调用就能获取用户图片的方式??
发布于 2014-03-20 19:48:55
谷歌已经改变了他们的政策,所以获取谷歌个人资料图像的旧方法现在不再有效,这是
https://plus.google.com/s2/photos/profile/(user_id)?sz=150
实现这一目标的新方法是
请求URL
https://www.googleapis.com/plus/v1/people/115950284...320?fields=image&key={YOUR_API_KEY}这将提供json格式的Google配置文件图像url,如下所示。
响应:
{
"image":
{
"url": "https://lh3.googleusercontent.com/-OkM...AANA/ltpH4BFZ2as/photo.jpg?sz=50"
}
}
您可能需要从here获取更多参数,以便与URL一起发送
有关更多详细信息,您还可以查看给定的问题,其中我已经回答了相同类型的问题How to get user image through user id in Google plus?
发布于 2012-06-28 00:10:25
更新:自2015年起,以下方法不起作用
可以获取头像,甚至可以设置头像的大小:
https://plus.google.com/s2/photos/profile/<user_id>?sz=<your_desired_size>示例:我的头像,大小设置为100像素:
https://plus.google.com/s2/photos/profile/116018066779980863044?sz=100使用镜像标签:
<img src="https://plus.google.com/s2/photos/profile/116018066779980863044?sz=100" width="100" height="100">希望你能让它工作起来!
发布于 2012-05-15 19:15:41
更新:谷歌停止了对此方法的支持,现在返回一个404 (未找到)错误。
所有这些urls都会获取用户的头像:
https://www.google.com/s2/photos/profile/{user_id}
https://plus.google.com/s2/photos/profile/{user_id}
https://profiles.google.com/s2/photos/profile/{user_id}它们重定向到您从Google API获得的同一图像url,这是一个丑陋的链接
lh6.googleusercontent.com/-x1W2-XNKA-A/AAAAAAAAAAI/AAAAAAAAAAA/ooSNulbLz8U/photo.jpg
最简单的是直接使用like图片源:
<img src="https://www.google.com/s2/photos/profile/{user_id}">否则,为了获得与Google API调用完全相同的url,您可以读取图像标题,
例如在PHP中:
$headers = get_headers("https://www.google.com/s2/photos/profile/{user_id}", 1);
echo "<img src=$headers[Location]>";如文章Fetch Google Plus Profile Picture using PHP所述。
https://stackoverflow.com/questions/9128700
复制相似问题