Programmatically getting an access token for using the Facebook Graph API

前端 未结 8 999
我在风中等你
我在风中等你 2020-12-04 09:06

I am trying to put together a bash or python script to play with the facebook graph API. Using the API looks simple, but I\'m having trouble setting up curl in my bash scrip

8条回答
  •  一整个雨季
    2020-12-04 09:48

    Here you go, as simple as it can get. Doesn’t require any 3rd-party SDK etc.

    Make sure Python 'requests' module is installed

    import requests
    
    def get_fb_token(app_id, app_secret):
        url = 'https://graph.facebook.com/oauth/access_token'       
        payload = {
            'grant_type': 'client_credentials',
            'client_id': app_id,
            'client_secret': app_secret
        }
        response = requests.post(url, params=payload)
        return response.json()['access_token']
    

提交回复
热议问题