instagram graph api rate limit execeed

54 Views Asked by At

I am using instagram graph api to extract data of my own account and other business accounts' media. During development, I have made couples of api calls to test the api, at first, everything works fine and the api response is returned successfully. All of the sudden, it is prompting request limit reached

{'error': {'message': '(#4) Application request limit reached', 'type': 'OAuthException', 'is_transient': True, 'code': 4, 'fbtrace_id': 'AMtO2GIogwSNpTD0-WqGny-'}}

Here is my python code to trigger the api call:

def get_url():
    print('access code url', access_url)
    code = input("enter the url")
    code = code.rsplit('access_token=')[1]
    code = code.rsplit('&data_access_expiration')[0]
    return code

def get_long_lived_access_token(
    access_token=''
):
    url = graph_url + 'oauth/access_token'
    params = dict()
    params['grant_type'] = 'fb_exchange_token'
    params['client_id'] = client_id
    params['client_secret'] = client_secret
    params['fb_exchange_token'] = access_token
    response = requests.get(url, headers=headers, params=params)
    response =response.json()
    long_lived_access_token = response['access_token']
    return long_lived_access_token

def get_page_id(
    access_token=''
):
    url = graph_url + 'me/accounts'
    params = dict()
    params['access_token'] = access_token
    response = requests.get(url, headers=headers, params=params)
    response = response.json()
    print(response)
    page_id = response['data'][0]['id']
    return page_id

access_token = get_url()
long_lived_access_token = get_long_lived_access_token(access_token=access_token)
page_id = get_page_id(access_token=long_lived_access_token)

Checking Application-Level Rate Limiting in meta developer dashboard, I can clearly see that there is still quota remaining: enter image description here

1

There are 1 best solutions below

0
Usman Ashraf On

The dashboard numbers can take a while before they catch up the actuals. You must be going overboard if you are receiving that error in your API response.

I suggest that you slow down your API hits by adding something like time.sleep(x) to the get_page_id() function. Here x will depend on the rate limit of the API endpoint you are using.

Let me know if you have any questions.

Related Questions in INSTAGRAM-GRAPH-API