我正在尝试获取 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/