0

I currently generate an access token in pretty much the same steps as @skylarcheung outline's here however I'd like to try to do this programatically instead of manually every 60 days. With access to the app id and secret, what call would I need to make to get the token, and then extend it?

Currently trying the following to get the token: response = requests.get(f"https://graph.facebook.com/oauth/access_token?client_id={app_id}&client_secret={app_secret}&grant_type=client_credentials")

but the returned app_token does not work when I try to pull political ads data or try to extend it: second_response = requests.get(f"https://graph.facebook.com/oauth/access_token?client_id={app_id}&client_secret={app_secret}&grant_type=fb_exchange_token&fb_exchange_token={app_token}") (The request to extend follows the code in this answer)

The error I get is:

{'error': {'message': 'Application does not have permission for this action', 'type': 'OAuthException', 'code': 10, 'error_subcode': 2332004, 'is_transient': False, 'error_user_title': 'App role required', 'error_user_msg': 'You need to be assigned a role by the app owner to continue. Learn more at https://developers.facebook.com/docs/development/build-and-test/app-roles', 'fbtrace_id': '*******'}}

(I am ID-verified to pull ads from the political ad library per the reqs and when I manually generate the token and extend it I am able to pull ads without issue)

jackstruck
  • 11
  • 2
  • 1
    please read [mcve] and adjust your question above accordingly. Good luck. – shellter Mar 25 '23 at 00:35
  • You need a user access token for these requests, but what you created is an app access token. (And no, you can not create user access tokens programmatically.) – CBroe Mar 28 '23 at 06:44

0 Answers0