{ "info": { "author": "Mike Helmick", "author_email": "me@michaelhelmick.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Topic :: Communications :: Chat", "Topic :: Internet", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Requests-Facebook\n=================\n\n\n``Requests-Facebook`` is a Python library to help interface with `Facebook Graph API `_ using the awesome ``requests`` library by `@kennethreitz `_\n\nFeatures\n--------\n\n* Authenticating Users\n* Dyanmic 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", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/michaelhelmick/requests-facebook/zipball/master", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/michaelhelmick/requests-facebook/", "keywords": "python facebook requests graph oauth oauth2 api", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "requests-facebook-py3", "package_url": "https://pypi.org/project/requests-facebook-py3/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/requests-facebook-py3/", "project_urls": { "Download": "https://github.com/michaelhelmick/requests-facebook/zipball/master", "Homepage": "https://github.com/michaelhelmick/requests-facebook/" }, "release_url": "https://pypi.org/project/requests-facebook-py3/0.2.1/", "requires_dist": null, "requires_python": null, "summary": "A Python Library to interface with Facebook Graph API", "version": "0.2.1" }, "last_serial": 1779634, "releases": { "0.2.1": [ { "comment_text": "", "digests": { "md5": "92a992409b9490c56ca8b9be7ddd0eb6", "sha256": "973b56be560d9fab64df4170e91303148fcf99699c8dc98e79f0ebe3dbd37585" }, "downloads": -1, "filename": "requests-facebook-py3-0.2.1.tar.gz", "has_sig": false, "md5_digest": "92a992409b9490c56ca8b9be7ddd0eb6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5656, "upload_time": "2015-10-21T09:26:25", "url": "https://files.pythonhosted.org/packages/81/ea/e4ff5b1f341a316e1cce70214922412ea7204494a9c611cb3c65b41285e0/requests-facebook-py3-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "92a992409b9490c56ca8b9be7ddd0eb6", "sha256": "973b56be560d9fab64df4170e91303148fcf99699c8dc98e79f0ebe3dbd37585" }, "downloads": -1, "filename": "requests-facebook-py3-0.2.1.tar.gz", "has_sig": false, "md5_digest": "92a992409b9490c56ca8b9be7ddd0eb6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5656, "upload_time": "2015-10-21T09:26:25", "url": "https://files.pythonhosted.org/packages/81/ea/e4ff5b1f341a316e1cce70214922412ea7204494a9c611cb3c65b41285e0/requests-facebook-py3-0.2.1.tar.gz" } ] }