Programmatically getting an access token for using the Facebook Graph API

前端 未结 8 1012
我在风中等你
我在风中等你 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:23

    s29 has the correct answer but leaves some steps to solve. The following script demonstrates a working script for acquiring an access token using the Facebook SDK:

    __requires__ = ['facebook-sdk']
    
    import os
    
    import facebook
    
    
    def get_app_access_token():
        client = facebook.GraphAPI()
        return client.get_app_access_token(
            os.environ['FACEBOOK_APP_ID'],
            os.environ['FACEBOOK_APP_SECRET'],
        )
    
    
    __name__ == '__main__' and print(get_app_access_token())
    

    This script expects the FACEBOOK_APP_ID and FACEBOOK_APP_SECRET environment variables are set to the values for your app. Feel free to adapt that technique to load those values from a different source.

    You must first install the Facebook SDK (pip install facebook-sdk; python get-token.py) or use another tool like rwt to invoke the script (rwt -- get-token.py).

提交回复
热议问题