Javascript 拉推特头像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2115084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pull twitter profile image
提问by HP.
Is there a quick way to pull twitter profile image in PHP or Javascript? I need to get the url of the FULL image (not avatar size). Thanks. Any code sample is good.
有没有一种快速的方法可以在 PHP 或 Javascript 中提取 twitter 个人资料图片?我需要获取完整图像的 url(不是头像大小)。谢谢。任何代码示例都很好。
回答by abraham
Twitter hashada nice simple URL.
推特 已有一个不错的简单网址。
https://api.twitter.com/1/users/profile_image/abraham
https://api.twitter.com/1/users/profile_image/abraham
It has size options like "?size=bigger"
它有像“?size=bigger”这样的尺寸选项
You can read more about it on Little known Twitter and TwitterAPI tips and tricks.
您可以在鲜为人知的 Twitter 和 TwitterAPI 提示和技巧中阅读更多相关信息。
Twitter now has documentation up as GET users/profile_image/:screen_name.
Twitter 现在将文档添加为GET users/profile_image/:screen_name。
Update: Support for this method has been removed from v1.1 of the API. Recommended practicegoing forward is GET /users/showand cache profile_image_urllocally in your service/app.
更新:已从 API 的 v1.1 中删除对此方法的支持。推荐的做法是GET /users/show并profile_image_url在您的服务/应用程序中本地缓存。
回答by Adam V.
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') should return a large avatar: http://a1.twimg.com/profile_images/330305510/n229938150541_9850_bigger.jpg
get_big_profile_image('bobsaget', '_bigger') 应该返回一个大头像:http://a1.twimg.com/profile_images/330305510/n229938150541_9850_bigger.jpg
get_big_profile_image('bobsaget') should return an even largerimage: http://a1.twimg.com/profile_images/330305510/n229938150541_9850.jpg
get_big_profile_image('bobsaget') 应该返回更大的图像:http: //a1.twimg.com/profile_images/330305510/n229938150541_9850.jpg
回答by Jordan
Apologies if this is something that's now known, but I didn't see it documented anywhere during my searches, including the official Twitter docs.
抱歉,如果这是现在已知的事情,但我在搜索过程中没有看到任何地方记录它,包括官方 Twitter 文档。
You can add the ?size=original as a parameter, which will return the original uploaded image for the user.
您可以添加 ?size=original 作为参数,它将为用户返回原始上传的图像。
So:
http://api.twitter.com/1/users/profile_image/twitter.json?size=original
所以:
http://api.twitter.com/1/users/profile_image/twitter.json?size=original
回答by texmex5
Previous answerers have provided the correct answer I wanted to link to original twitter api doc page so you'd know it is actually an official way of doing stuff:
以前的回答者提供了我想链接到原始 twitter api 文档页面的正确答案,所以你会知道它实际上是一种官方的做事方式:
You need to specify ?size=
您需要指定 ?size=
- bigger - 73px by 73px
- normal - 48px by 48px
- mini - 24px by 24px
- 更大 - 73px x 73px
- 正常 - 48 像素 x 48 像素
- 迷你 - 24 像素 x 24 像素
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://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
http://dev.twitter.com/doc/get/users/profile_image/:screen_name
回答by rrbrambley
So, it's not in the docs (http://dev.twitter.com/doc/get/users/profile_image/:screen_name), but it looks like after retrieving the image by specifying any of the three sizes (bigger, normal, mini), you can just remove the suffix before the file extension to get the original image. Hmm... is this safe to use?
因此,它不在文档中 (http://dev.twitter.com/doc/get/users/profile_image/:screen_name),但在通过指定三种尺寸(更大、正常、 mini),您可以删除文件扩展名前的后缀以获得原始图像。嗯……这可以安全使用吗?
For example, this query: api.twitter.com/1/users/profile_image/rrbrambley
例如,这个查询:api.twitter.com/1/users/profile_image/rrbrambley
Results in: a2.twimg.com/profile_images/931772958/deformed_cropped_headonly_normal.jpg
结果在:a2.twimg.com/profile_images/931772958/deformed_cropped_headonly_normal.jpg
If I change this url by removing "_normal" then I get the original image: a2.twimg.com/profile_images/931772958/deformed_cropped_headonly.jpg
如果我通过删除“_normal”来更改这个 url,那么我会得到原始图像:a2.twimg.com/profile_images/931772958/deformed_cropped_headonly.jpg
I know there are apps that use the original image. This must be the way?
我知道有些应用程序使用原始图像。这一定是方法?
回答by JohnyFree
When you get original image link, you can modify it to get bigger. http://pbs.twimg.com/profile_images/34543543/image_name_normal.jpg
当您获得原始图像链接时,您可以对其进行修改以变大。 http://pbs.twimg.com/profile_images/34543543/image_name_normal.jpg
becomes
变成
http://pbs.twimg.com/profile_images/34543543/image_name.jpgor image_name_bigger, ...
http://pbs.twimg.com/profile_images/34543543/image_name.jpg或 image_name_bigger,...
Source: https://dev.twitter.com/docs/user-profile-images-and-banners
来源:https: //dev.twitter.com/docs/user-profile-images-and-banners
回答by Eric
I know this isn't the full code sample as requested (because there are several ways of doing this), but do you already have the URL for the avatar? I noticed that turning ".../eric.png" into ".../eric_bigger.png" resulted in the larger image. When "_bigger" already exists, removing it gave me the URL to the original image.
我知道这不是所要求的完整代码示例(因为有多种方法可以做到这一点),但是您是否已经拥有头像的 URL?我注意到将“.../eric.png”变成“.../eric_bigger.png”会产生更大的图像。当“_bigger”已经存在时,删除它会给我原始图像的 URL。
I tested this with several followers' profile images and, when the profile image was > 150px square, worked.
我用几个关注者的个人资料图片对此进行了测试,当个人资料图片大于 150 像素方形时,就可以了。
回答by tapeshwar
Twitter profile images urls: Bigger:https://api.twitter.com/1/users/profile_image/puneetsindhwani/?size=biggerOriginal:https://api.twitter.com/1/users/profile_image/puneetsindhwani/?size=original
Twitter 个人资料图片网址: 更大:https : //api.twitter.com/1/users/profile_image/puneetsindhwani/? size =bigger原始:https : //api.twitter.com/1/users/profile_image/puneetsindhwani/?大小=原始

