Skip to main content

A Python wrapper for the Facebook & Instagram Graph APIs.

Build Status Documentation Status Codecov PyPI

Introduction

We have refactored this library after v0.10.0. If you want to use the old version, please, see branch v0.

The new structure is as follows

docs/docs/images/structure.png

Installing

You can install this library from pypi:

pip install --upgrade python-facebook-api

Usage

GraphAPI

You can use the GraphAPI class to communicate with the Facebook Graph API.

You can initialize a GraphAPI object with three different methods, depending on your needs.

  1. If you already have an access token, you can initialize it with

    >>> from pyfacebook import GraphAPI
    >>> api = GraphAPI(access_token="token")
  2. 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)
  3. 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, see https://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.

FacebookAPI

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.

Features

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

SUPPORT

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.

Jetbrains

Release files for python-facebook-api 0.24.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-facebook-api 0.24.0
File Size Uploaded
python_facebook_api-0.24.0.tar.gz 56.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-facebook-api 0.24.0
File Interpreter ABI Platform
python_facebook_api-0.24.0-py3-none-any.whl Python 3 none any Details

Total release size: 135.2 kB

Release files / python_facebook_api-0.24.0.tar.gz

Download URL python_facebook_api-0.24.0.tar.gz
Size 56.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b78ca54017a6849306cc94b886369b3fc82c975a382fa4e22241a83849b61226
BLAKE2b-256 checksum
How to use checksums
05b06eb9b99b21c23bdabd2f9731596d51674174b53b3a14d0118ecdb12cdfc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.11.0 Linux/6.11.0-1018-azure

Release files / python_facebook_api-0.24.0-py3-none-any.whl

Download URL python_facebook_api-0.24.0-py3-none-any.whl
Size 78.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e512483c33688abe537f34341afd2dcb9766675bbf8c2ce02544dc9252913308
BLAKE2b-256 checksum
How to use checksums
d18784ccb52c732ad82ba85d92214355b90c8bb1788e23e0657b10d579881664
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.11.0 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

0.24.0 This release

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.17.1

2 release files

0.15.0

2 release files

0.14.3

2 release files

0.14.2

2 release files

0.14.1

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.2

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page