有没有办法建立一个具有用户ID或屏幕名称的个人资料图片网址?我将用户ID存储在数据库中,但我不想存储配置文件图像URL。
编辑: 我也不想打电话给api。我想把user_id放在一个url里面
<img src="https://twitter.com/users/profile_pic?user_id=123">
有这样的网址吗?
使用API 1.1,您可以使用此URL实现
https://twitter.com/[screen_name]/profile_image?size=mini https://twitter.com/[screen_name]/profile_image?size=normal https://twitter.com/[screen_name]/profile_image?size=bigger https://twitter.com/[screen_name]/profile_image?size=original
Official twitter documentation Profile Images and Banners
例
https://twitter.com/TwitterEng/profile_image?size=original
将重定向到
https://pbs.twimg.com/profile_images/875168599299637248/84CkAq6s.jpg
介绍在没有Twitter API的情况下获取Twitter Profile Image的最简单方法。
作为@AlexB,@ jfred表示它在MOBILE设备上根本不起作用。
在单页中使用通用框架PHP或Javascript获取重定向URL是一种非常难的方法。
只需在您的图片标签中注述http://avatars.io/twitter/ruucm
。
喜欢
<img src="https://avatars.io/twitter/ruucm" alt="twt_profile" border="0" width="259"/>
我已经测试过Angular 2+它可以解决任何问题
你可以使用users/show
method of the Twitter API获得它 - 它完全按照你的描述。你给它一个ID或屏幕名称,它返回一堆数据,包括profile_image_url
。
根据@ Cristiana214的回答
以下PHP代码段可用于使https://twitter.com/[screen_name]/profile_image?size=normal技巧在移动设备上运行。
由于twitters重定向到移动版本的网站链接,如https://twitter.com/[screen_name]/profile_image?size=normal在移动设备上被打破
因此脚本获取重定向响应(到用户头像)提取地址然后重定向页面本身
if (!isset($_GET['id'])) $_GET['id'] = 'twitter';
$urlget = curl_init();
curl_setopt($urlget, CURLOPT_URL, 'https://twitter.com/' . $_GET['id'] . '/profile_image?size=normal');
curl_setopt($urlget, CURLOPT_HEADER, true);
curl_setopt($urlget, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($urlget);
preg_match_all("/location: (.*)/", $res, $found);
header('Location: ' . $found[1][0]);
所以这可以作为twitteravatar.php?id = twitter访问(在撰写本文时)重新加载到https://pbs.twimg.com/profile_images/767879603977191425/29zfZY6I_normal.jpg
不漂亮但有效。
没有办法做到这一点。事实上,Twitter没有像facebook那样提供网址(https://graph.facebook.com/ /?fields = picture)
问题是报告,但状态是:'WontFix',看看:
好吧,我通过PHP Dom Parser使用了一个棘手的方法
include('simple_html_dom.php');
$html = file_get_html('http://twitter.com/mnckry');
$img = array();
foreach($html->find('img.size73') as $e)
$img[] = $e->src;
foreach($html->find('.profile-header-inner') as $e)
$img[] = str_replace("')", "", str_replace("url('", "", $e->{'data-background-image'}));
echo $img[0];//Avatar
echo "<br>";
echo end($img);//ProfileBG
这会给你这样的东西; https://pbs.twimg.com/profile_images/378800000487958092/e04a191de329fcf8d000ca03073ad594_bigger.png
获得另外2个尺寸;对于大版本删除,较小版本的“_bigger”将“_bigger”替换为“_normal”
在1.1版本中,使用http://a0.twimg.com/profile_images/XXXXX/afpecvf41m8f0juql78p_normal.png,其中XXXXX是用户ID