Search code examples
facebook-graph-apiinstagram-graph-api

Facebook API Graph. Instagram. How to get user profile picture knowing only username?


I'm implementing webhook subscription to receive notifications about new comments on Instagram media (so, the solution assumes server side environment). Webhook payload contains a comment ID. Fetching a comment node via Facebbok API Graph call I can get author's username. From this point I need to get author's profile picture.

Currently I can use Business Discovery API to get information about user by username like this

GET graph.facebook.com/%PAGEID%
    ?fields=business_discovery.username(%USERNAME%){...fields...} 

But this method is working only for Instagram Business accounts.

Recently, this task can be accomplished with https://www.instagram.com/%USERNAME%/?__a=1 call, but now this request requires authorization.


Solution

  • You cannot get the user profile picture by using the username, because facebook denies querying users by their username:

    (#803) Cannot query users by their username
    

    Even if, indeed, getting the facebook picture of a user does not require an access token or any permissions.

    You need to get the userid (10000xxxxxxxxxx), and then you'd be able to:

    GET https://graph.facebook.com/v3.2/{userid}/picture