{"id":17197138,"url":"https://github.com/michaelhelmick/requests-facebook","last_synced_at":"2025-04-13T19:31:08.167Z","repository":{"id":57461333,"uuid":"4578200","full_name":"michaelhelmick/requests-facebook","owner":"michaelhelmick","description":"A Python Library to interface with Facebook Graph API","archived":false,"fork":false,"pushed_at":"2018-01-16T16:34:41.000Z","size":18,"stargazers_count":73,"open_issues_count":0,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-27T10:11:53.213Z","etag":null,"topics":["api","facebook","graph","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelhelmick.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-06T21:26:11.000Z","updated_at":"2024-08-27T09:30:47.000Z","dependencies_parsed_at":"2022-09-17T04:30:55.677Z","dependency_job_id":null,"html_url":"https://github.com/michaelhelmick/requests-facebook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelhelmick%2Frequests-facebook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelhelmick%2Frequests-facebook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelhelmick%2Frequests-facebook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelhelmick%2Frequests-facebook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelhelmick","download_url":"https://codeload.github.com/michaelhelmick/requests-facebook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154984,"owners_count":21056543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","facebook","graph","python"],"created_at":"2024-10-15T01:55:34.040Z","updated_at":"2025-04-13T19:31:07.943Z","avatar_url":"https://github.com/michaelhelmick.png","language":"Python","readme":"Requests-Facebook\n=================\n\n\n``Requests-Facebook`` is a Python library to help interface with the `Facebook Graph API \u003chttps://graph.facebook.com\u003e`_ using the awesome ``requests`` library by `@kennethreitz \u003chttps://github.com/kennethreitz\u003e`_\n\nFeatures\n--------\n\n* Authenticating Users\n* Dynamic Facebook methods\n   - Read home feeds/user feeds\n   - Post status updates\n   - Delete items\n   - Like items\n   - And many more!!\n* Photo Uploading\n\n\nInstallation\n------------\n\nInstalling Requests-Facebook is simple: ::\n\n    $ pip install requests-facebook\n\n\nUsage\n-----\n\nAuthorization URL\n~~~~~~~~~~~~~~~~~\n\n::\n\n    f = FacebookAPI(client_id='*your app key*',\n                    client_secret='*your app secret*',\n                    redirect_uri='http://example.com/callback/')\n\nor\n\n::\n\n    f = FacebookAPI('*your app key*', '*your app secret*', 'http://example.com/callback/')\n\n::\n\n    auth_url = f.get_auth_url(scope=['publish_stream', 'user_photos', 'user_status'])\n    \n    print 'Connect with Facebook via: %s' % auth_url\n\nOnce 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.\n\nHandling the Callback\n~~~~~~~~~~~~~~~~~~~~~\n::\n\n    # Assume you are using the FacebookAPI object from the Authorization URL code\n\n    # You'll need to obtain `code` from the url query string\n\n    # In Django, you'd do something like\n    # code = request.GET.get('code')\n\n    access_token = f.get_access_token(code)\n    \n    final_access_token = access_token['access_token']\n    \n    # Save that token to the database for a later use?\n\n\nDynamic Facebook methods\n~~~~~~~~~~~~~~~~~~~~~~~~\nSay you have the url ``https://graph.facebook.com/me/friends``\nTo make a call via this library, you'd do ``GraphAPI.get('me/friends')``\n\nYou just take everything in the url *AFTER* ``https://graph.facebook.com/``\n\nGetting some User information\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n::\n\n    # Get the final tokens from the database or wherever you have them stored\n\n    graph = GraphAPI(access_token)\n\n    # Print out your information\n    try:\n        print graph.get('me')\n    except FacebookClientError:\n        print 'Failed! :('\n\n    # Print out my information\n    print graph.get('mikehimself')\n\n\nGetting your Home Feed\n~~~~~~~~~~~~~~~~~~~~~~\n::\n\n    # Assume you are using the GraphAPI instance from the previous section\n    home_feed = graph.get('me/home')\n    print home_feed\n\nGetting a Profile Feed\n~~~~~~~~~~~~~~~~~~~~~~\n::\n\n    # Assume you are using the GraphAPI instance from the previous section\n    your_feed = graph.get('me/feed')\n    print your_feed\n\n    # Getting my profile feed\n    my_feed = graph.get('mikehimself/feed')\n    print my_feed\n\nCreating a Photo Album\n~~~~~~~~~~~~~~~~~~~~~~\n::\n\n    # Assume you are using the GraphAPI instance from the previous section\n    new_album = graph.post('me/albums', params={'name':'Test Album'})\n    print new_album\n\nPosting a Photo\n~~~~~~~~~~~~~~~\n::\n\n    # Assume you are using the GraphAPI instance from the previous section\n    # Assume you are using the album you just created in the previous section\n\n    # new_album = new_album var from the previous section\n    album_id = new_album['id']\n\n    photo = open('path/to/file/image.jpg', 'rb')\n\n    # The file key that Facebook expects is 'source', so 'source' will be apart\n    # of the params dict.\n\n    # You can pass any object that has a read() function (like a StringIO object)\n    # In case you wanted to resize it first or something!\n\n    new_photo = graph.post('%s/photos' % album_id, params={'message':'My photo caption!', 'source': photo})\n\n    print new_photo\n\n\nPosting an Edited Photo *(This example resizes a photo)*\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n::\n\n    # Assume you are using the GraphAPI instance from the previous section\n    # Assume you are using the album you just created in the previous sections\n\n    # Like I said in the previous section, you can pass any object that has a\n    # read() method\n\n    # Assume you are working with a JPEG\n\n    from PIL import Image\n    from StringIO import StringIO\n\n    photo = Image.open('/path/to/file/image.jpg')\n\n    basewidth = 320\n    wpercent = (basewidth / float(photo.size[0]))\n    height = int((float(photo.size[1]) * float(wpercent)))\n    photo = photo.resize((basewidth, height), Image.ANTIALIAS)\n\n    image_io = StringIO.StringIO()\n    photo.save(image_io, format='JPEG')\n    \n    image_io.seek(0)\n\n    try:\n        new_photo = graph.post('%s/photos' % album_id, params={'message':'My photo caption!', 'source': photo})\n    except FacebookClientError, e:\n        # Maybe the file was invalid?\n        print e.message\n\n\nCatching errors **(In case you didn't catch it in the first example)**\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n::\n\n    # Assume you are using the GraphAPI instance from the previous section\n\n    try:\n        graph.delete('me/feed')\n    except FacebookClientError, e:\n        print e.message\n        print 'Something bad happened :('\n\n\nTODO\n----\nSupport for Facebook REST API\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelhelmick%2Frequests-facebook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelhelmick%2Frequests-facebook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelhelmick%2Frequests-facebook/lists"}