Search code examples
facebookfacebook-graph-api

Get user profile picture by Id


I'm now working on a web application which is mostly based of facebook graph api. I hold some data about users - actually , the possible public data available - such as name and id. I also know that a profile picture is a part of the public data, and I wondered how I'll be able to get a direct link to a profile picture of a user only by using their id?


Solution

  • http://graph.facebook.com/" + facebookId + "/picture?type=square For instance: http://graph.facebook.com/67563683055/picture?type=square

    There are also more sizes besides "square". See the docs.

    Update September 2020
    As Facebook have updated their docs this method is not working anymore without a token. You need to append some kind of access_token. You can find further information and how to do it correctly in the fb docs to the graph api of user picture

    Requirements Change This endpoint supports App-Scoped User IDs (ASID), User IDs (UID), and Page-Scoped User IDs (PSID). Currently you can query ASIDs and UIDs with no requirements. However, beginning October 24, 2020, an access token will be required for all UID-based queries. If you query a UID and thus must include a token:

    use a User access token for Facebook Login authenticated requests
    use a Page access token for page-scoped requests
    use an App access token for server-side requests
    use a Client access token for mobile or web client-side requests

    Quote of fb docs