- Notifications
You must be signed in to change notification settings - Fork92
A simple Python wrapper for facebook graph api ✨ 🍰 ✨ .
sns-sdks/python-facebook
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Python wrapper for the Facebook & Instagram Graph APIs.
We have refactored this library after v0.10.0. If you want to use the old version, please, see branchv0.
The new structure is as follows
Note
This new structure may still change.
Now, you can use base classGraphAPI to get data.
You can install this library frompypi:
pip install --upgrade python-facebook-api
Note
If you want to use an old version, you can set the version to0.9.*, which also supports Python 2.7.
You can use theGraphAPI class to communicate with the Facebook Graph API.
You can initialize aGraphAPI object with three different methods, depending on your needs.
If you already have an access token, you can initialize it with
>>> from pyfacebook import GraphAPI>>> api = GraphAPI(access_token="token")
If you need to generate an app token automatically using the app/client ID and secret, you can do
>>> from pyfacebook import GraphAPI>>> api = GraphAPI(app_id="id", app_secret="secret", application_only_auth=True)
If you want to perform the authorization process for a user, you can do
>>> from pyfacebook import GraphAPI>>> api = GraphAPI(app_id="id", app_secret="secret", oauth_flow=True)>>> api.get_authorization_url()# ('https://www.facebook.com/dialog/oauth?response_type=code&client_id=id&redirect_uri=https%3A%2F%2Flocalhost%2F&scope=public_profile&state=PyFacebook', 'PyFacebook')# let user to do oauth at the browser opened by link.# then get the response url>>> api.exchange_user_access_token(response="url redirected")# Now the api will get the user access token.
For more info about the different access tokens, seehttps://developers.facebook.com/docs/facebook-login/guides/access-tokens.
Once you have the user access token, you can get the Facebook data. For example,
>>> api.get_object(object_id="20531316728")>>> {'name':'Facebook App','id':'20531316728'}
See the code for more operations.
To get the user data:
>>> fb.user.get_info(user_id="413140042878187")>>> User(id='413140042878187', name='Kun Liu')
To get the page data:
>>> fb.page.get_info(page_id="20531316728")>>> Page(id='20531316728', name='Facebook App')
For more info, please, see the code or the docs.
The library has the following features.
Facebook Graph API:
- Application and Application's edges
- Page and Page's edges
- User and User's edges
- Group and Group's edges
- Event and Event's edges
- Server-Sent Events
IG Business Graph API:
- User and User's edges
- Media and Media's edges
IG Basic Display API:
- User and User's edges
- Media and Media's edges
python-facebook-api has been developed with Pycharm under the free JetBrains Open Source license(s) granted by JetBrains s.r.o.,hence I would like to express my thanks here.
About
A simple Python wrapper for facebook graph api ✨ 🍰 ✨ .
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors5
Uh oh!
There was an error while loading.Please reload this page.
