Automatically post to facebook page using python

I want to make a script that allows me to post on my facebook page (which I am the administrator)

As far as I understand, most api api examples are based on creating facebook python applications and allow them to communicate with python, which is very different from what I want.

Also, the api schedule requires the oauth token, as the documentation claims it received:

https://www.facebook.com/dialog/oauth ? client_id = YOUR_APP_ID & redirect_uri = YOUR_URL

I think it means:

a) I have to create a facebook app for this that I didn’t think was necessary (after all, this is something that will only require my standard credentials and will not be used by other people), but that’s good. I have an application created for this task.

b) I need a URL that I don’t have because it is just a script.

Any ideas on where I should look for information?

+5
source share
1 answer

First you need to get your Facebook_App_Id and Facebook_App_Secret, from facebook, which you will receive when registering your application.

Then you include the required URLs.

redirect_client_url = 'http://your-redirect-url'
access_token_url = 'https://graph.facebook.com/oauth/access_token?client_id='+consumer_key+'&redirect_uri='+red   irect_client_url+'&client_secret='+consumer_secret+'&code='
scope = 'publish_stream,offline_access,user_birthday,email'
authorize_url = 'https://graph.facebook.com/oauth/authorize?client_id='+consumer_key+'&redirect_uri='+redirect_client_url+'&scope='+scope+'&display=touch'
user_info_url = 'https://graph.facebook.com/me?access_token='

Your consumer’s key and consumer’s secret is the secret code of the Facebook and facebook app.

access_token, Oauth2.0, access_token fan, . https://github.com/simplegeo/python-oauth2 - , oauth. , , , - .

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('https://graph.facebook.com/%s' % request_path, post_data)

. , - - .

+6

All Articles