How do I access Facebook wall feed in python? - python

I am trying to make a little desktop alert script that will tell me if there is a new post on my Facebook page's wall. It would be nice to see if I'm getting any new likes as well but really I mostly want to access my wall feed.
I don't need help parsing it or anything like that (I'm literally just going to compare a stored feed with how it is currently to see if there is a change once every 2 minutes or so) I just need to know how to access it.

You can pull the content in your profile feed (wall) as a JSON object using the Facebook Graph API. You can check out the details here: http://developers.facebook.com/docs/reference/api/

Like McOcoonor said you should use the Facebook Graph API as documented here:
http://developers.facebook.com/docs/reference/api/
If you want your application to have continuous, long-term access to your Facebook information then you need to add the offline_access permission flag to when the app requests the access token. Documented here:
https://developers.facebook.com/docs/authentication/permissions/
For doing this all in Python you might be interested in this S.A. Question: Facebook Graph API and Django.

You can try to use a library to access your facebook wall. It requires register your application on facebook but it's easy to do http://developers.facebook.com/setup/
Then you can check out a python wrapper to the facebook api -> http://code.google.com/p/pyfb/
Or download it from pypi -> sudo pip install pyfb

If you are using facebook sdk for python (https://github.com/mobolic/facebook-sdk), you can use get_connections method(http://facebook-sdk.readthedocs.io/en/latest/api.html#get-connections)
import facebook
graph = facebook.GraphAPI(access_token)
feeds = graph.get_connections('me', 'feed')

Related

OAUTH2 Python Facebook Login

I am new to web programming- I've recently been familiarizing myself with the webapp2 framework. I'm trying to start building a website, and would like users to login to the site with Facebook and I'll need access to their friends list. I've been trying to find a way to do this- I found out about OAUTH2, and I think this may be a way to do this. All the tutorials for python and OAUTH2 that I've found have been using the google API, I'm not sure if it's any different, but I haven't been able to get it to work.
Does anyone have sample code they can post that uses OAUTH2 (or anything else) to get users to sign in through Facebook? Or any good resources that can help me with this?
Your app needs to authorize users with Facebook, since there's where the resources you need are (e.g. friend lists).
This is a classic use of OAuth2 and you don't have a way around it, because FB implements this protocol.
My suggestion is that you look at the Google sample and then adjust it for FB API. The important changes are:
The endpoint URLs (e.g. authorize, token and user profile
The scopes that define the extent of permissions you are requesting (e.g. list of friends)
The user profile (e.g. the information returned by FB on a user: name, e-mail, etc)
This is a very simple sample that does this in Python. It was meant to run in Google App Engine. The only caveat is that it uses our own library to encapsulate the flow. But you can use it to study how the basic protocol works. Run the live demo and turn on dev tools on your browser to see the network activity.
You will notice that OAuth2 is a rather simple protocol, using simple HTTP requests.

Facebook friend handling via python and GraphAPI

i am learning about handling the graph api in python via the FacePy module.
I am just curious as to see if it was possible to delete friends via the Graph API?
Because of possible misuse that might happen, feature like deleting friends via Facebook is not available. You can although send Friend Requests but the app should not use this feature to encourage users to friend other users that they are not connected to in real life.

What python library I should use for facebook OAuth and OpenGraph

I have designed a Facebook application and need to add OAuth, Open Graph for complete functionality. Considering that I know nothing about Open Graph and little JS, I'd like to use a small wrap-up (python lib) which will provide the those features..
I searched over Google, stackoverflow and found few projects which provide some cool features but I am unable to choose..
python libs:
django-social-auth
fandjango
facepy
pyFacebook - I think this doesn't offer OAuth.
I also use Google Data API in my project. So, the better option would be django-social-auth but I am not sure if I can do Open Graph with it..
Can anyone tell me what is the best, maintained, good lib?
(Please do mention if its not in the above list)
django-social-auth is really great if you want to build a website that allows users to log in with Facebook, but if you're building an application on Facebook.com you probably want to use something like fandjango. Either way, you will need a different kind of library (like, say, facepy) to interact with Facebook's API once you've retrieved an access token from the user.
Full disclosure: I am the author of fandjango and facepy.
I would highly suggest django-social-auth. Any library than can parse JSON will support Open Graph as FQL and Graph API data can all be retrieved from Facebook's API (REST).
Good luck!

Getting Started with Facebook API

I have a friend that owns a small business and has a Page on Facebook. I want to help her manage it from a marketing perspective, and figure that it may be best to do so through their API.
I have skimmed their API documentation, and have a basic working knowledge of Python. What I can't figure out is if I can access their page's data with Python and grab the data on wall posts, who liked posts, etc. Is this possible? I can't find a decent tutorial for someone who is new to programming.
To provide context, I have been scraping the Twitter Search API for some time now and I am hoping there is something similar (request certain data elements, and have it returned as structured data I can analyze). I find their API extremely straight forward, and for Facebook, I don't know where to begin.
I don't want to create an application, I simply want to access the data that is related to my friend's page.
I am hoping to find some decent tutorials and help on what I will need to get started. Any help you can provide will be greatly appreciated.
You could try Pyjamas Desktop.
http://pyjs.org/
It runs python in an embedded web browser and gives you access to the html DOM.
This potentially means that you can use the JS api directly from python.
You will need to be running a server locally though.
Basically to automate posting stuff to the persons profile you need to get their oath token and then make API calls w/ that token.
Here are steps to get API token:
Register APP w/ facebook and get app id
Have your friend click this link https://www.facebook.com/dialog/oauth?
client_id=[your app id here]&
type=user_agent&
scope=email,read_stream,,,user_about_me,offline_access,publish_stream&
redirect_uri=http://www.facebook.com/connect/login_success.html
Then record that token for future
You can now use any available python FB lib to post and manage that FB page.
This should get you started:
http://eggie5.com/20-getting-started-w-facebook-api

What's the easiest way to get my facebook status and photos using python?

I just want to import my facebook status and photos to my personal django website but all the examples and documentation i can find are for developing facebook applications.
A simple rss feed would be enough but it doesnt seem to exist in facebook.
Do i really have to create a full facebook app to do this?
A simple facebook application isn't that hard ... excluding trying to decipher the soup on developers.facebook.com.
The "problem" is that you need to get an application key, application secret, and sometimes a session key in order to access the web services. Unless someone is sharing a service to do just that (I haven't looked, and you'd need to trust them) then the only way to fulfill the requirements are to create an application. However, the application key/application secret don't actually require that you write anything. They will show up in the Facebook Developer Application (the application that allows you to edit your applications...)
Now, all you need is a session key (however, a session key is not always required, see the Understanding Sessions link below) -- and hopefully a permanent one. To do this, ask for the extended offline_access permission**. If you grant that to an application then it can get a session for you whenever it feels like it (or rather, the session does not follow the one-hour expiration policies for that application). Extended permissions. Understanding Sessions. Oh, but ignore that 'auth.renewOfflineSession(UID)' example -- the method doesn't exist. I told you the "developer" documentation was soup :-)
You can use the URL in format:
http://www.facebook.com/tos.php?api_key=YOURAPIKEY&req_perms=offline_access to request the permission of yourself. Now see the links below :-)
Extra information in:
**I'm not entirely sure if new changes to the FB policy affect forever-sessions, but this link seems more than relevant to the task at hand:
http://blog.jylin.com/2009/10/01/loading-wall-posts-using-facebookstream_get/
Getting offline_access to work with Facebook
Facebook offline access step-by-step
(You need never post/share your facebook application -- you can keep it in sandbox mode forever.)
Probably. Anything that bypassed authentication would be a fairly large privacy issue.
With the release of the new graph api, this is pretty simple once you get your oauth token. Unfortunately you will need to create an app, but it can be a rather small one to get your oauth token so facebook can authorize your requests. You can use the python sdk here: http://github.com/facebook/python-sdk/
Once you have your token, you make a call to: https://graph.facebook.com/[your profile]/statuses?token=[your token]
And you will get json back.
If you first login to facebook and then go to the documentation page you can see the working example by clicking on the statuses link in the connections table.
http://developers.facebook.com/docs/reference/api/user

Categories

Resources