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

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

问题描述

我正在开发一个应用程序,它使用 facebook 登录.登录后,用户必须设置附加信息和个人资料图片,图片也来自登录的 facebook 帐户.现在,整个帐户详细信息,包括该个人资料图片的 URL,都保存在我的数据库中.

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

https://scontent.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/p720x720/10846350_10204966809307370_2779189783437306470_n.jpg?25a125a26e5a26e8fb26e5a26e5a26e8fbc26e8fbc26e5a26e8fbc95a26e5a26e5a26e5a26e8fbcdn>8fbc96e下载这些照片并将它们保存到我自己的服务器对我来说并不是一个真正的选择.我可以做些什么来使该 URL 持久化?

解决方案

是的,Facebook 的 CDN URL 可能会过期 - 您不应该存储它们以供长期使用.

但是您可以请求任何用户的个人资料图片(只要您拥有他们的全局/应用范围的用户 ID),只需参考

https://graph.facebook.com/4/picture//马克·扎克伯格的头像

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

虽然那张图片很小,50px x 50px – 您可以使用 https://graph.facebook.com/4/picture?type=large 请求更大的版本.这将为您提供 200 像素 x 200 像素(或接近该值,如果用户没有上传方形图片)的个人资料图片.

请注意,某些图片需要获取访问令牌.例如 https://graph.facebook.com/72256131540/picture除非您添加这样的访问令牌,否则将返回问号的通用图像:

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

更新:

如果您通过应用范围的用户 ID 请求个人资料图片,这应该仍然可以正常工作.如果您通过旧的全局用户 ID 或页面范围的用户 ID 请求它,那么您现在必须包含访问令牌 - https://developers.facebook.com/docs/graph-api/reference/user/picture#requirements 有详细信息.>

(应用或页面访问令牌不应在公共客户端代码中公开,因此在使用这些令牌时,应仅在服务器端发出请求.)

I'm developing an app, which uses the facebook login. After login the user must set additional informations and a profile picture, with the picture being provided from that logged in facebook account as well. Now the whole account details, including the URL to that profile picture, are saved in my database.

To my surprise the profile picture has suddenly stopped working. Opening it's URL in a browser gives me this message "URL signature expired"

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 应用程序登录:如何控制我获得的图像 URL 的到期日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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