If you need to automatically publish something on your facebook wall or facebook pages wall, you can follow these steps:
Get your Facebook App Id and App Secret
You can get them from your facebook app, if you don’t have any then you can go to this page https://developers.facebook.com/apps and create new application.
Grant permission to write to the wall
You need to make sure that your application has write permission to the wall. You can use this url to grant your application write permission.
http://www.facebook.com/connect/prompt_permissions.php?api_key=YOUR_FACEBOOK_APP_ID&v=1.0&next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&display=page&ext_perm=publish_stream,offline_access&enable_profile_selector=1&profile_selector_ids=PROFILE_ID_OF_WALL
Python script to publish something on facebook wall
You can use and modify this script according to your need. Don’t forget to install python sdk from https://github.com/facebook/python-sdk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import facebook import urllib import urlparse FACEBOOK_APP_ID = 'YOUR_FACEBOOK_APP_ID' FACEBOOK_APP_SECRET = 'YOUR_FACEBOOK_APP_SECRET' FACEBOOK_PROFILE_ID = 'PROFILE_ID_OF_WALL' oauth_args = dict(client_id = FACEBOOK_APP_ID, client_secret = FACEBOOK_APP_SECRET, grant_type = 'client_credentials') oauth_response = urllib.urlopen('https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(oauth_args)).read() try: oauth_access_token = urlparse.parse_qs(str(oauth_response))['access_token'][0] except KeyError: pass facebook_graph = facebook.GraphAPI(oauth_access_token) try: response = facebook_graph.put_wall_post('hello world', profile_id = FACEBOOK_PROFILE_ID) except facebook.GraphAPIError as e: print e |
That’s it. See you around.
Related posts:
This is a well written article that I have bookmarked for future reference. Have a fun.
I just added this blog to my feed reader, excellent stuff. Cannot get enough!
This code working well but when i tested it under google app engine python not worked. I suppose, not-standard urllib of google app engine caused this.