https://github.com/eventbrite/facebook-py-sdk
Facebook Python SDK
https://github.com/eventbrite/facebook-py-sdk
facebook facebook-api facebook-graph-api facebook-sdk python
Last synced: 9 days ago
JSON representation
Facebook Python SDK
- Host: GitHub
- URL: https://github.com/eventbrite/facebook-py-sdk
- Owner: eventbrite
- License: mit
- Created: 2016-09-06T02:54:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-01-12T11:33:59.000Z (almost 2 years ago)
- Last Synced: 2025-03-11T01:56:57.590Z (10 months ago)
- Topics: facebook, facebook-api, facebook-graph-api, facebook-sdk, python
- Language: Python
- Homepage:
- Size: 98.6 KB
- Stars: 1
- Watchers: 17
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.txt
- License: LICENSE
Awesome Lists containing this project
README
Facebook SDK Python
===================
.. image:: https://travis-ci.org/eventbrite/facebook-py-sdk.svg?branch=master
:target: https://travis-ci.org/eventbrite/facebook-py-sdk
.. image:: https://coveralls.io/repos/github/eventbrite/facebook-py-sdk/badge.svg
:target: https://coveralls.io/github/eventbrite/facebook-py-sdk
Facebook SDK Python is a python based implementation of `Facebook PHP SDK`_
.. contents:: Table of Contents
Installation
============
To install Facebook SDK Python, simply:
.. code-block:: bash
$ pip install facebook-py-sdk
Usage
=====
Retrieve User Profile
---------------------
.. code-block:: python
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
------------------
.. code-block:: python
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:
* requests_
.. _requests: http://docs.python-requests.org/en/latest/
.. _Facebook PHP SDK: https://developers.facebook.com/docs/reference/php/
Contributing
============
Please use github model by forking the repository and making Pull Requests.
Running tests
-------------
.. code-block:: bash
➜ facebook-python-sdk $ pip install -e .[testing]
➜ facebook-python-sdk $ pytest