requests-facebookA Python Library to interface with Facebook Graph API | |
Download |
requests-facebook Ranking & Summary
Advertisement
- License:
- MIT/X Consortium Lic...
- Price:
- FREE
- Publisher Name:
- Mike Helmick
- Publisher web site:
- https://github.com/michaelhelmick/
requests-facebook Tags
requests-facebook Description
requests-facebook is a Python library to help interface with Facebook Graph API.InstallationInstalling Requests-Facebook is simple: pip install requests-facebookUsageAuthorization URLf = FacebookAPI(client_id='*your app key*', client_secret='*your app secret*', redirect_uri='http://example.com/callback/')orf = FacebookAPI('*your app key*', '*your app secret*', 'http://example.com/callback/')auth_url = f.get_auth_url(scope=)print 'Connect with Facebook via: %s' % auth_urlOnce you click "Allow" be sure that there is a URL set up to handle getting finalized access_token and possibly adding it to your database to access their information at a later date.Handling the Callback# Assume you are using the FacebookAPI object from the Authorization URL code# You'll need to obtain `code` from the url query string# In Django, you'd do something like# code = request.GET.get('code')access_token = f.get_access_token(code)final_access_token = access_token# Save that token to the database for a later use?Dynamic Facebook methodsSay you have the url https://graph.facebook.com/me/friends To make a call via this library, you'd do GraphAPI.get('me/friends')You just take everything in the url AFTER https://graph.facebook.com/Getting some User information# Get the final tokens from the database or wherever you have them storedgraph = GraphAPI(access_token)# Print out your informationtry: print graph.get('me')except FacebookClientError: print 'Failed! :('# Print out my informationprint graph.get('mikehimself')Getting your Home Feed# Assume you are using the GraphAPI instance from the previous sectionhome_feed = graph.get('me/home')print home_feedGetting a Profile Feed# Assume you are using the GraphAPI instance from the previous sectionyour_feed = graph.get('me/feed')print your_feed# Getting my profile feedmy_feed = graph.get('mikehimself/feed')print my_feedCreating a Photo Album# Assume you are using the GraphAPI instance from the previous sectionnew_album = graph.post('me/albums', params={'name':'Test Album'})print new_albumCreating a post with a photo# Assume you are using the GraphAPI instance from the previous section# Assume you are using the album you just created in the previous section# new_album = new_album var from the previous sectionalbum_id = new_album# Files is a list of dicts in the case that you can upload multiple filesfiles = new_photo = graph.post('%s/photos' % album_id, params={'message':'My photo caption!'}, files=files)print new_photoCatching errors (In case you didn't catch it in the first example)# Assume you are using the GraphAPI instance from the previous sectiontry: graph.delete('me/feed')except FacebookClientError, e: print e.message print 'Something bad happened :('Product's homepage
requests-facebook Related Software