-2

I am trying to get some details ( username, description, Posts Count, total likes & total comments ) from Instagram user

  1. First i get the code from api.instagram.com with scope user_profile and user_media https://api.instagram.com/oauth/authorize?client_id={appId}&redirect_uri={redirectUri}&scope=user_profile,user_media&response_type=code

  2. After the user accepts the permission and allows the sharing of information it I got the code in my redirectUri.

  3. then using that code and developer auth details I get the access_token by

    https://api.instagram.com/oauth/access_token endpoint with fields client_id, redirect_uri, grant_type = authorization_code, client_secret and the code. in response, I got the user_id and the access_token.

  4. Then I try to get the username and user details by calling the below endpoint Refrence

    https://graph.instagram.com/me?fields=id,username&access_token={access_token}. in response, I got the username and id.

  5. Now I am not sure how to get the details like ( username, description, Posts Count, total likes & total comments ).

What I have tried

  1. I try to get the details by calling the https://www.instagram.com/someone/?__a=1 it works fine sometimes but now it's not returning anything.
  2. Instagram Graph Api in this I am getting the error the access token is not valid. ( not sure which access token to user Instagrams or facebooks )
NikuNj Rathod
  • 1,663
  • 1
  • 17
  • 26

1 Answers1

0

You're currently using the Instagram Basic Display APIs (official docs) which are highly limited and do not include any of the information you seek, apart from the username.

Instagram chose not to include this information in the Instagram Basic Display APIs, while they offer them in the Instagram Graph API (official docs) instead.

However, the Instagram Graph API only works with Business and Creators accounts, therefore you can not use it for most Instagram users.

Furthermore the 2 APIs do not communicate with each other, so you can not use the Basic Display Token on the Graph token, even if the user is business.

Bottom line:

  • if you're planning to retrieve this information for normal users (non-business and non-creators), you won't be able to use any official API
  • if you're planning to retrieve this information only for business or creator accounts, you need to switch your entire logic to the Instagram Graph API, including the login flow, which needs to happen via Facebook => Page connected to IG.

It's a pity, I know, but that's the current situation.

EDIT: scraping from https://www.instagram.com/someone/?__a=1 is very complicated, Instagram has a great anti-crawling policy and will block scraping very well.

Andrea Olivato
  • 2,450
  • 1
  • 18
  • 30