Facebook App Login: How to control expiration date of an image URL I got?

前端 未结 1 483
借酒劲吻你
借酒劲吻你 2020-12-30 01:12

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

相关标签:
1条回答
  • 2020-12-30 01:27

    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.)

    0 讨论(0)
提交回复
热议问题