Bruno Bruno - 1 year ago 103
Python Question

Automatically posting to facebook page with python

I want to make a script that lets me post to my facebook fan page (which I'm an admin of)

As far as I've seen, Most graph api examples are about making facebook apps in python and make them communicate with python, which is quite different from what I want.

Also The graph api requires the oauth token, which the documentation claims it's obtained by doing:

I think this implies:

a) I HAVE to create a facebook app for this, which I didn't think it was necessary (after all it's something that would require only my standard credentials and wouldn't be used by other people), but it is fine. I have an app created for this task.

b) I need an URL, which I don't have, because it's just a script.

Any ideas on where I should look for some info?

Answer Source

First You need to get your Facebook_App_Id and Facebook_App_Secret, from facebook which you will get when you register your app.

Then you include the needed urls.

redirect_client_url = 'http://your-redirect-url'
access_token_url = ''+consumer_key+'&redirect_uri='+red   irect_client_url+'&client_secret='+consumer_secret+'&code='
scope = 'publish_stream,offline_access,user_birthday,email'
authorize_url = ''+consumer_key+'&redirect_uri='+redirect_client_url+'&scope='+scope+'&display=touch'
user_info_url = ''

Your consumer key and consumer secret are the Facebook app id and facebook app secret respectively.

You would basically get the access_token following the Oauth2.0 guidelines and store the access_token and fan page idsomewhere in your database. is a good example on how to get the oauth token. Then when you try to post use the access token by using something like this.

post_data = {'access_token':access_token, 'message':'hey this is a test!'}
request_path = str(facebook_id)+'/feed'
post_data = urllib.urlencode(post_data)
response = urllib2.urlopen('' % request_path, post_data)

This should work for posting to a user's wall. But i am sure posting to a facebook fan page should be something very similar.