0

i have a python script "script.py" which do some processing on a closed group of Facebook which I am an admin of, the script does a routine check every 30 minutes.

Till now i was using Graph API explorer access token to authorize the script. Now i want to deploy this script on a server so that it runs automatically after every 30 minutes forever, i will be using heroku server to host my python script

I have read that i would want a access_token which don't expire, for that an app is needed and now i am confused with all the Facebook is using. I found thisfacebook-permanent-page-access-token . On it's 3rd sub-step of step 1, it asks to "setup a website app", this is quite vague for me.

Can anyone explain how i can do this ?

  • When you get the access_token you can request facebook to give long live access token. Is that what you want ? – Raja Simon May 29 '17 at 07:39
  • You don't need to create a real "website app". You only need to create a Facebook App and use the app id and secret to follow through the steps you found. – Shang May 29 '17 at 07:39
  • @RajaSimon i think that would work, but how to get it ? – Ashwani Gautam May 29 '17 at 09:37

1 Answers1

0

After getting the access_token you can make another request to fb with grant_type, client_id, client_secret, fb_exchange_token...

i.e )

ENDPOINT = 'https://graph.facebook.com/v2.9/oauth/access_token'
params = {
    'grant_type': 'fb_exchange_token',
    'client_id': app_id,
    'client_secret': client_secret,
    'fb_exchange_token': access_token
}
return requests.get(ENDPOINT, params=params).json()
Raja Simon
  • 9,102
  • 3
  • 31
  • 70
  • I should use my app name instead of graph API explorer to het the access token right ?. When i do this, i get an access token with very basic permissions, i need just one additional permission, when i request for the access token with additonal permissions, another pop-up says me to submit my app for an review, but you see i have just one script not an entire app. What should i do ? – Ashwani Gautam May 29 '17 at 13:14
  • One script or entire app is doesn't matter. If you want long live after getting the access_token make another call that I shown you. – Raja Simon May 29 '17 at 13:16
  • If another submit app for review clearly indicating that permission needs approval. – Raja Simon May 29 '17 at 13:17
  • @AshwaniGautam Did you get long access token ? – Raja Simon May 30 '17 at 07:40
  • Yes, i got a long-live access token, which i have to refresh every 2 months. I didn't submitted my app for review, because i do not intend to publish it and thus i was able to get access token with additional permissions. Also is there a way we can also get initial access_token programmatically ?, today i just copy pasted the access_token from explorer tools – Ashwani Gautam May 30 '17 at 09:51