拉推特个人资料图片

时间:2010-01-22 04:56:38

标签: php javascript html api twitter

有没有快速的方法在PHP或Javascript中提取推特个人资料图片?我需要获取完整图像的网址(不是头像大小)。谢谢。任何代码示例都很好。

8 个答案:

答案 0 :(得分:46)

Twitter 已经 拥有一个不错的简单网址。

https://api.twitter.com/1/users/profile_image/abraham

它有大小选项,如“?size = greater”

您可以在Little known Twitter and TwitterAPI tips and tricks上了解更多相关信息。

Twitter现在的文档为GET users/profile_image/:screen_name

更新:已从API的v1.1中删除对此方法的支持。 Recommended practice前进GET /users/show并在您的服务/应用中本地缓存profile_image_url

答案 1 :(得分:12)

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

答案 2 :(得分:5)

以前的回答者提供了我想要链接到原始twitter api文档页面的正确答案,所以你知道它实际上是一种正式的做事方式:

您需要指定?size=

  • 更大 - 73px乘73px
  • 正常 - 48px乘48px
  • mini - 24px by 24px
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

答案 3 :(得分:5)

道歉,如果这是现在已知的事情,但我没有在我的搜索过程中看到任何记录,包括官方的Twitter文档。

您可以添加?size = original作为参数,该参数将返回用户的原始上传图像。

所以: http://api.twitter.com/1/users/profile_image/twitter.json?size=original

答案 4 :(得分:2)

所以,它不在文档中(http://dev.twitter.com/doc/get/users/profile_image/:screen_name),但它看起来像是通过指定三种尺寸中的任何一种来检索图像(更大) ,normal,mini),您可以在文件扩展名之前删除后缀以获取原始图像。嗯......这样安全吗?

例如,此查询:api.twitter.com/1/users/profile_image/rrbrambley

结果:a2.twimg.com/profile_images/931772958/deformed_cropped_headonly_normal.jpg

如果我通过删除“_normal”更改此网址,则会显示原始图片:a2.twimg.com/profile_images/931772958/deformed_cropped_headonly.jpg

我知道有些应用使用原始图片。这一定是这样的吗?

答案 5 :(得分:1)

答案 6 :(得分:0)

我知道这不是所要求的完整代码示例(因为有几种方法可以做到这一点),但您是否已经拥有了头像的URL?我注意到将“... / eric.png”变成“... / eric_bigger.png”导致图像变大。当“_bigger”已经存在时,删除它会给我原始图像的URL。

我用几个关注者的个人资料图片测试了这个,当个人资料图片是> 150px square,work。

答案 7 :(得分:-1)