缓存http://graph.facebook.com/[UID]/图片调用?

发布于 2024-10-15 03:11:09 字数 1194 浏览 1 评论 0原文

感谢 如何使用 facebook graph api 显示用户个人资料图片? 我发现我可以通过以下方式检索个人资料图片

http://graph.facebook.com/[UID]/picture

,但这会重定向到一个图像,例如:

http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_14868 35_q.jpg

我的第一个问题是,当我想显示此图像时,我应该这样做(从 API 返回)

<img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg" />

还是应该调用 api:

<img src="http://graph.facebook.com/alfredwesterveld/picture" />

http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg 显示我的更新的个人资料图片,如果更新我在 Facebook 上的个人资料图片或确实显示我的旧个人资料图片。我问这些问题是因为当我可以调用绝对 URL(立即解析为图像)时,我可以安全地进行重定向(往返)。我相信这可能会增加,特别是当我想从我的网站访问者那里获取所有个人资料图片时。

Thanks to How can I display the users profile pic using the facebook graph api? I found out I can retrieve profile picture via

http://graph.facebook.com/[UID]/picture

but this redirects to an image like for example:

http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg

My first question is when I want to display this image should I do(returned from API)

<img src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg" />

or should I call the api:

<img src="http://graph.facebook.com/alfredwesterveld/picture" />

Does http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1346.snc4/161671_1096373372_1486835_q.jpg show my updated profile picture, if update my profile picture on Facebook or does show my old profile picture. I ask these question because when I could call an absolute URL(which resolves to an image immediately) I could safe myself a redirect(round-trip). I believe this could add up especially when I want to get all profile pictures from the visitors of my website.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

站稳脚跟 2024-10-22 03:11:10

你好,为什么你不使用 fbml 标签呢?

<fb:profile-pic uid='UID' width='50' height='50'></fb:profile-pic>

编辑
您好,如果您想获取用户上传的照片,那么您可以通过此获取

$photos=json_decode(file_get_contents('https://graph.facebook.com/me/photos?access_token='.$cookie['access_token']));
foreach ($photos->data as $friend)
{
?>
<img src="<?=$friend->source?>" width="50" height="50">
<?php    
}

用户上传的所有图像都可以轻松捕获

hi why you not use fbml tag for this?

<fb:profile-pic uid='UID' width='50' height='50'></fb:profile-pic>

EDIT
hello if you want to get photo uploaded by the user then you can get by this

$photos=json_decode(file_get_contents('https://graph.facebook.com/me/photos?access_token='.$cookie['access_token']));
foreach ($photos->data as $friend)
{
?>
<img src="<?=$friend->source?>" width="50" height="50">
<?php    
}

All images uploaded by the user can be easily captured

嗳卜坏 2024-10-22 03:11:09

当您想使用第二种方法显示用户的图片时,这是一个好的方法:

<img src="https://graph.facebook.com/[UID]/picture" alt="" />

这样做您将确保每次您都会收到用户的更新图片(如果最近更改过)。

稍后编辑

与缓存问题相关,如果您想保存直接网址以改善图片缓存,我不建议这样做,因为每次用户更改个人资料时这些网址都会发生变化图片,因此您最终可能会显示旧图片,即使用户最近实际上更改了它。

When you want to display the picture of a user use the second method, that's the good one:

<img src="https://graph.facebook.com/[UID]/picture" alt="" />

Doing like this you'll be sure that each time you'll receive the updated picture of the user, if it was changed recently.

later edit

Related to the cache issue, if you want to save the direct urls in order to improve caching of the pictures I don't suggest doing so because those urls are changing each time a user changes the profile picture, so you might end up displaying an older picture even though the user actually changed it recently.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文