How to connect to Facebook Graph API from Python using Requests if I do not need user access token?
Question: I am trying to find the easiest way how to use Facebook Graph API using my
favorite [Requests](http://docs.python-requests.org/) library. The problem is,
all examples I found are about getting **user access token** , about redirects
and user interaction.

All I need is only **application access token**. I do not handle any non-
public data, so I need no user interaction and as my final app is supposed to
be command-line script, no redirects are desired.

I found something similar
[here](http://stackoverflow.com/questions/3058723/programmatically-getting-an-
access-token-for-using-the-facebook-graph-api), but it seems to be everything
but elegant. Moreover, I would prefer something using
[Requests](http://docs.python-requests.org/) or [Requests-
OAuth2](https://github.com/maraujop/requests-oauth2). Or maybe there is
library for that? I found [Requests-
Facebook](https://github.com/maraujop/requests-oauth2) and
[Facepy](https://github.com/jgorset/facepy) (both Requests based), but again,
all examples are with redirection, etc. Facepy does not handle authorization
at all, it just accepts your token and it is up to you to get it somehow.

Could someone, please, provide a short, sane, working example how to get just
the application access token?


Answer: 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.

