How to connect to Facebook Graph API from Python using Requests if I do not need user access token?

前端 未结 2 840
你的背包
你的背包 2020-12-28 10:08

I am trying to find the easiest way how to use Facebook Graph API using my favorite Requests library. The problem is, all examples I found are about getting user acc

相关标签:
2条回答
  • 2020-12-28 10:45

    Following https://developers.facebook.com/docs/technical-guides/opengraph/publishing-with-app-token/:

    import requests
    r = requests.get('https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=123&client_secret=XXX')
    access_token = r.text.split('=')[1]
    print access_token
    

    (using the correct values for client_id and client_secret) gives me something that looks like an access token.

    0 讨论(0)
  • 2020-12-28 10:52

    If you just need a quick/small request, you can manually cut and paste the access token from here into you code: https://developers.facebook.com/tools/explorer

    Note: Unlike Richard Barnett's answer, you'll need to regenerate the code manually from the graph api explorer every time you use it.

    0 讨论(0)
提交回复
热议问题