Skip to main content

Facebook Python SDK

Project description

Facebook SDK Python

https://travis-ci.org/eventbrite/facebook-py-sdk.svg?branch=master https://coveralls.io/repos/github/eventbrite/facebook-py-sdk/badge.svg

Facebook SDK Python is a python based implementation of Facebook PHP SDK

Installation

To install Facebook SDK Python, simply:

$ pip install facebook-py-sdk

Usage

Retrieve User Profile

from facebook_sdk.exceptions import FacebookResponseException
from facebook_sdk.facebook import Facebook

facebook = Facebook(
    app_id='{app_id}',
    app_secret='{app_secret}',
    default_graph_version='v2.12',
)

facebook.set_default_access_token(access_token='{access_token}')

try:
    response = facebook.get(endpoint='/me?fields=id,name')
except FacebookResponseException as e:
    print(e.message)
else:
    print('User id: %(name)s' % {'name': response.json_body.get('id')})
    print('User name: %(name)s' % {'name': response.json_body.get('name')})

Batch Upload Files

from facebook_sdk.exceptions import FacebookResponseException
from facebook_sdk.facebook import Facebook

facebook = Facebook(
    app_id='{app_id}',
    app_secret='{app_secret}',
)

facebook.set_default_access_token(access_token='{access_token}')

batch = {
    'photo-one': facebook.request(
        endpoint='/me/photos',
        params={
            'message': 'Foo photo.',
            'source': facebook.file_to_upload('path/to/foo.jpg'),
        },
    ),
    'photo-two': facebook.request(
        endpoint='/me/photos',
        params={
            'message': 'Bar photo.',
            'source': facebook.file_to_upload('path/to/bar.jpg'),
        },
    ),
    'photo-three': facebook.request(
        endpoint='/me/photos',
        params={
            'message': 'Other photo.',
            'source': facebook.file_to_upload('path/to/other.jpg'),
        },
    )
}

try:
    responses = facebook.send_batch_request(requests=batch)
except FacebookResponseException as e:
    print(e.message)

Dependencies

Dependencies that to use the application:

Contributing

Please use github model by forking the repository and making Pull Requests.

Running tests

  facebook-python-sdk $ pip install -e .[testing]
  facebook-python-sdk $ pytest

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

facebook-py-sdk-1.1.2.tar.gz (11.3 kB view details)

Uploaded Source

File details

Details for the file facebook-py-sdk-1.1.2.tar.gz.

File metadata

  • Download URL: facebook-py-sdk-1.1.2.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.7

File hashes

Hashes for facebook-py-sdk-1.1.2.tar.gz
Algorithm Hash digest
SHA256 3145e73785e2e90b7f937c9ff41360712ea3ea9a1a0ab40956d03bda50c042b0
MD5 2cb3bfcd2021e669e1286ff088023002
BLAKE2b-256 b30c7f6e973d216cb57653320058aedd5a74e339c30b50194e2f5bb6404c31ef

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