![](/img/trans.png)
[英]Zend Twitter Feed how to pull users profile image along with post
[英]Pull twitter profile image
有没有快速的方法来在PHP或Javascript中提取twitter个人资料图片? 我需要获取完整图像的网址(不是头像大小)。 谢谢。 任何代码示例都很好。
推特 具有 有一个很好的简单网址。
https://api.twitter.com/1/users/profile_image/abraham
它有像“?size = larger”这样的尺寸选项
您可以在鲜为人知的Twitter和TwitterAPI提示和技巧上阅读更多相关信息。
Twitter现在有文档作为GET用户/ profile_image /:screen_name 。
更新 :已从API的v1.1中删除对此方法的支持。 今后推荐的做法是在您的服务/应用中本地GET / users / show和cache profile_image_url
。
function get_big_profile_image($username, $size = '') {
$api_call = 'http://twitter.com/users/show/'.$username.'.json';
$results = json_decode(file_get_contents($api_call));
return str_replace('_normal', $size, $results->profile_image_url);
}
get_big_profile_image('bobsaget','_ bigger')应该返回一个大头像: http ://a1.twimg.com/profile_images/330305510/n229938150541_9850_bigger.jpg
get_big_profile_image('bobsaget')应该返回一个更大的图像: http ://a1.twimg.com/profile_images/330305510/n229938150541_9850.jpg
以前的回答者提供了我想要链接到原始的twitter api doc页面的正确答案,所以你知道它实际上是一种正式的做事方式:
你需要指定?size=
http://api.twitter.com/1/users/profile_image/twitter.json?size=bigger http://api.twitter.com/1/users/profile_image/twitter.json?size=normal
http://dev.twitter.com/doc/get/users/profile_image/:screen_name
如果这是现在已知的事情,请道歉,但我在搜索过程中没有看到它记录在案,包括官方的Twitter文档。
您可以添加?size = original作为参数,该参数将返回用户的原始上传图像。
所以: http://api.twitter.com/1/users/profile_image/twitter.json?size=original
: http://api.twitter.com/1/users/profile_image/twitter.json?size=original
所以,它不在文档中(http://dev.twitter.com/doc/get/users/profile_image/:screen_name),但看起来像是通过指定三种尺寸中的任何一种来检索图像(更大,更正常, mini),您可以在文件扩展名之前删除后缀以获取原始图像。 嗯......这样安全吗?
例如,此查询:api.twitter.com/1/users/profile_image/rrbrambley
结果于:a2.twimg.com/profile_images/931772958/deformed_cropped_headonly_normal.jpg
如果我通过删除“_normal”来更改此URL,那么我将获得原始图像:a2.twimg.com/profile_images/931772958/deformed_cropped_headonly.jpg
我知道有些应用程序使用原始图像。 这一定是这样的吗?
当您获得原始图像链接时,您可以将其修改为更大。 http://pbs.twimg.com/profile_images/34543543/image_name_normal.jpg
变
http://pbs.twimg.com/profile_images/34543543/image_name.jpg或image_name_bigger,...
资料来源: https : //dev.twitter.com/docs/user-profile-images-and-banners
我知道这不是所要求的完整代码示例(因为有几种方法可以做到这一点),但您是否已经拥有了头像的URL? 我注意到将“... / eric.png”变成“... / eric_bigger.png”导致图像变大。 当“_bigger”已经存在时,删除它会给我原始图像的URL。
我用几个粉丝的个人资料图片测试了这个,当个人资料图片大于150像素时,工作。
Twitter个人资料图片网址: 更大: https : //api.twitter.com/1/users/profile_image/puneetsindhwani/? size = bigger 原文: https : //api.twitter.com/1/users/profile_image/puneetsindhwani/?大小=原
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.