Facebook App登录:如何控制我获得的图像URL的到期日期? [英] Facebook App Login: How to control expiration date of an image URL I got?

查看:175
本文介绍了Facebook App登录:如何控制我获得的图像URL的到期日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Facebook登录名的应用程序.登录后,用户必须设置其他信息和个人资料图片,该图片也由登录的Facebook帐户提供.现在,整个帐户详细信息(包括该个人资料图片的URL)都保存在我的数据库中.

令我惊讶的是,个人资料图片突然停止工作.在浏览器中打开它的URL会给我以下消息:"URL签名已过期"

解决方案

是的,Facebook的CDN URL可能会过期-您不应将其存储为长期使用.

但是,您可以通过简单地引用

来请求任何用户的个人资料图片(只要您具有其全局/应用范围的用户ID)即可.

https://graph.facebook.com/4/picture // Mark Zuckerberg’s profile pic

–该URL发出重定向到该图像的当前CDN URL.

该图像相当小,为50px x 50px –您可以使用https://graph.facebook.com/4/picture?type=large请求更大的版本.这样一来,您的个人资料图片将为200px x 200px(如果用户未上传方形图片,则可以接近该图片)

请注意,某些图片需要检索访问令牌.例如https://graph.facebook.com/72256131540/picture 返回问号的通用图像,除非您添加如下访问令牌:

https://graph.facebook.com/72256131540/picture?access_token=<ACCESS_TOKEN>

更新:

如果您通过应用程序范围内的用户ID请求个人资料图片,则此方法仍然可以正常工作而不会出现问题.如果要通过旧的全局用户ID或页面范围的用户ID进行请求,则必须现在包含访问令牌-

https://scontent.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/p720x720/10846350_10204966809307370_2779189783437306470_n.jpg?oh=245bbada6c23f280a1e531e724be85ed&oe=56894D69

Downloading those photos and save them to my own server is not really an option for me. Is there anything I can do to make that URL durable?

解决方案

Yes, Facebook’s CDN URLs may expire - you are not supposed to store them for long-term use.

But you can request any user’s profile picture (as long as you have their global/app-scoped user id), by simply referring to

https://graph.facebook.com/4/picture // Mark Zuckerberg’s profile pic

– that URL issues a redirect to the current CDN URL for the image.

That image is rather small though, 50px x 50px – you can use https://graph.facebook.com/4/picture?type=large to request a larger version. That will give you the profile image in 200px x 200px (or close to that, if the user did not upload a square image.)

Note that some pictures require an access token to be retrieved. For example https://graph.facebook.com/72256131540/picture returns a generic image of a questionmark unless you add an access token like this:

https://graph.facebook.com/72256131540/picture?access_token=<ACCESS_TOKEN>

UPDATE:

This should still work the same without problems, if you are requesting the profile picture via an app-scoped user ID. If you are requesting it via an old, global user ID or a page-scoped user id, then you will have to include an access token now - https://developers.facebook.com/docs/graph-api/reference/user/picture#requirements has the details.

(App or page access tokens should not be exposed in public client-side code, so when using those, the request should be made only server-side.)

这篇关于Facebook App登录:如何控制我获得的图像URL的到期日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆