How can I display the users profile pic using the facebook graph api?

前端 未结 9 602
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 07:24

I would like to display the users profile picture inside of my applications canvas page, is there a way to do that using the graph api?

I know I can do it using FBML

相关标签:
9条回答
  • 2020-12-02 07:59

    EDIT: So facebook has changed it again! No more searching by username - have amended the answer below...

    https://graph.facebook.com/{{UID}}/picture?redirect=false&height=200&width=200
    
    • UID = the profile or page id
    • redirect either returns json (false) or redirects to the image (true)
    • height and width is the crop
    • does not require authentication

    e.g. https://graph.facebook.com/4/picture?redirect=false&height=200&width=200

    Facebook Graph picture doc

    0 讨论(0)
  • 2020-12-02 07:59

    One very important thing is that like other Graph API request, you won't get the JSON data in response, rather the call returns a HTTP REDIRECT to the URL of the profile pic. So, if you want to fetch the URL, you either need to read the response HTTP header or you can use FQLs.

    0 讨论(0)
  • 2020-12-02 08:04

    You can also resize the profile picture by providing parameters as shown below.

    https://graph.facebook.com/[UID]/picture?width=140&height=140
    

    would work too.

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