Skip to main content

A simple Python wrapper around the Facebook Graph API

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_facebook_api-0.20.1.tar.gz (58.9 kB view details)

Uploaded Source

Built Distribution

python_facebook_api-0.20.1-py3-none-any.whl (78.6 kB view details)

Uploaded Python 3

File details

Details for the file python_facebook_api-0.20.1.tar.gz.

File metadata

  • Download URL: python_facebook_api-0.20.1.tar.gz
  • Upload date:
  • Size: 58.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Linux/6.8.0-1014-azure

File hashes

Hashes for python_facebook_api-0.20.1.tar.gz
Algorithm Hash digest
SHA256 96617a9f4cd8ff1744b501feb450e38056401cce78652aae1b55e281beb458ca
MD5 2fa444605fd15a37618078fdfe8f2620
BLAKE2b-256 33750d4a9075a1f7c25e3ea9481fcca0dc48465bbeffee8da09457f232e939fd

See more details on using hashes here.

File details

Details for the file python_facebook_api-0.20.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_facebook_api-0.20.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e44fd90c7e4ddbc1d6928f35490d4cbf7ff4a9a20453a0eb235ac4e11c45367b
MD5 56c4002a0fc550c347d17650345c8e78
BLAKE2b-256 5e05b7458e4424824b2e4c87e9f84899d7a73ebb1b16e3f33d59cfbe0405b06a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page