php - 获取 Twitter 个人资料图片实际链接

标签 php twitter file-get-contents

我正在尝试获取 Twitter 个人资料图片的实际链接。 我知道我可以通过以下链接获取个人资料图片:

 $test = "http://api.twitter.com/1/users/profile_image?screen_name=".$nickname."&size=original"

但是当我想获取这个url的文件内容时,它不起作用,因为上面提到的链接被重定向到个人资料图片的实际链接。所以这不起作用:

  file_get_contents($test);     

如何获取个人资料图片的实际链接以及原始尺寸?

最佳答案

试试这个可能会对你有帮助。

<?php
function getTwitterProfileImage($username) {
      $size = '_bigger';
      $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);
}
$img =  getTwitterProfileImage('thetutlage');
echo '<img src="'.$img.'"/>';
 ?>

关于php - 获取 Twitter 个人资料图片实际链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11565416/

相关文章:

php - Laravel - 我的每个服务容器/自定义类都需要一个服务提供商吗?

php - 初始 Symfony2 安装中没有样式或图像?

php - 在 php 中循环 - 创建不同的卷号

php - 使用 PayPal API 检查信用卡类型(Mastercard vs Visa)

Node.js 推特客户端

javascript - NodeJS Twitter API 客户端返回不同的 next_cursor 和 next_cursor_str 值

php - file_get_contents - 下载文件名中包含空格的文件不起作用

python - 从 appengine + python 发送推文

php - 即使使用了我在网上发现的所有技巧,警告也没有得到抑制

PHP 从另一个网站上的特定类中抓取文本