Facebook Python SDK
Project description
Facebook SDK Python
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
Release history Release notifications | RSS feed
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.0.tar.gz
(12.1 kB
view details)
File details
Details for the file facebook-py-sdk-1.1.0.tar.gz
.
File metadata
- Download URL: facebook-py-sdk-1.1.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 067f7715526ee812d8905ab5db5558eb355b6af122871f817a7e58f04db84756 |
|
MD5 | 17913e4e89c00ddfaf5ea759799687a1 |
|
BLAKE2b-256 | 2b87b46dfe5d64550c3da26687323d0cca90e713bad11487e77364a60f67a4c4 |