Search code examples
pythoninstagram-api

how get the number follower Instagram with Python


I need to find the number of followers of an account Instagram with python3 I know that Instagram has changed the political access .

I tried to download https://www.instagram.com/user/?__a=1

from bs4 import BeautifulSoup
import requests
import json

# instagram URL
URL = 'https://www.instagram.com/user/?__a=1'

query = "selenium"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'}
url = 'https://www.google.com?q=' + query
res = requests.get(URL, headers=headers)

response = json.loads(res.text)
print(response)

Nevertheless , i can't find the number of followers .

I create an account on developers.facebook.com . I have an API with ID and secret code. Nevertheless , I didn't look a good example.


Solution

  • You can try to get the Instagram account info by using the facebook-business-sdk for python. If your IG Account is connected via Facebook, you can get the info in this way:

    session = FacebookSession(
    config['app_id'],
    config['app_secret'],
    config['access_token'],
    )
    api = FacebookAdsApi(session)
    
    fb_account = AdAccount("act_***") # Your FB account_id
    ig_account = fb_account.get_connected_instagram_accounts(
                            fields=["followers_count"])
    

    You can find the list of fields here.