Created
April 16, 2018 07:30
-
-
Save Fast0n/8f399b4773f2f3169383caab3184c485 to your computer and use it in GitHub Desktop.
FacePyExample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from facepy import GraphAPI | |
# Initialize the Graph API with a valid access token (optional, | |
# but will allow you to do all sorts of fun stuff). | |
graph = GraphAPI("") | |
# Get my latest posts | |
last_posts = graph.get('me/posts') | |
message = last_posts['data'][0]['message'] | |
story = last_posts['data'][0]['story'] | |
created_time = last_posts['data'][0]['created_time'] | |
id_post = last_posts['data'][0]['id'] | |
num_post = len(last_posts['data']) | |
# Post a text | |
# NB. Supported value are EVERYONE, ALL_FRIENDS, FRIENDS_OF_FRIENDS, CUSTOM, SELF | |
graph.post( | |
path='me/feed', | |
message="Hello World!", | |
link="www.github.com/fast0n", | |
privacy={"value": "EVERYONE"}, | |
retry=0 | |
) | |
# Create photo/video albums | |
# NB. Supported value are EVERYONE, ALL_FRIENDS, FRIENDS_OF_FRIENDS, CUSTOM, SELF | |
result_create_album = graph.post( | |
path='me/albums', | |
privacy={"value": "EVERYONE"}, | |
name='My New Album' | |
) | |
id_album = result_create_album['id'] | |
# Post a photo/video of a python | |
graph.post( | |
caption='caption', | |
path=id_album + '/photos', | |
# path='me/photos', | |
source=open('python.png', 'rb') | |
) | |
# Edit caption post | |
graph.post( | |
path = 'id_post', | |
message='Hello World!' | |
) | |
# Delete my latest post | |
result_delete = graph.delete( | |
path=last_posts['data'][0]['id'] | |
) | |
# Search | |
# NB. Supported only place type | |
# ps. Types as post, user, event, group, checkin have been deprecated | |
result_search = graph.search( | |
term='name', | |
type='place', | |
page=False | |
) | |
try: | |
if result_search['data'][0]['category'] != 0: | |
print(result_search['data']) | |
except: | |
print("Has been deprecated") | |
last_posts = graph.get('me/posts') | |
id_post = last_posts['data'][0]['id'] | |
print (id_post) | |
# Like a post | |
graph.post( | |
path=id_post+'/likes', | |
retry=0 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment