Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API)
February 23, 2010 | python, toolsauthor: Karol Zielinski | comments: 29 | views: 8736
Tags: facebook, facebook api, fan page, python, rest
After long days (or even weeks) of fighting with this issue… today I can be proud of myself. At last… I did it and it works! I can publish new posts on Facebook Page wall as a Page, not as a user (admin of that page).
I found lots of discussions about that, however none of them were enough for me. Some of the discussions:
And now… my solution:
Log in to Facebook, create new app, create fan page.
Now you are ready.
Go to http://www.facebook.com/apps/application.php?id=ID_OF_YOUR_APP.
Find link ‘Add to my Page’ on the left, click on it. Find your page on the list and click on ‘Add to page’ next to this page.
Go to http://www.facebook.com/developers/editapp.php?app_id=ID_OF_YOUR_APP.
Choose ‘Web’ next to ‘Application type’ and click on ‘Save Changes’ button.
Prepare special link:
replace YOUR_API_KEY for an API KEY of your application and ID_OF_YOUR_PAGE for an id of your page
Run this URL in your web browser. Click on ‘Allow’.
You should see a message: ‘Success’.
Go to http://developers.facebook.com/tools.php?app_id=335851346097 and check your permissions.
Choose your application, change ‘Response Format’ to JSON, choose method ‘users.hasAppPermission’, fill publish_stream in ext_perm and id of your page in uid.
You should see result: 1.
That means that everything is ok.
Right now I will show how to create script in python (with PyFacebook), but the code is really similar to that from other programming languages.
def add_to_fb();
import facebook
fb = facebook.Facebook('YOUR_API_KEY', 'YOUR_SECRET_KEY')
fb.auth.createToken()
fb.login(popup=False)
#print 'offline access...'
#b.request_extended_permission('offline_access')
#print 'publish stream...'
#fb.request_extended_permission('publish_stream')
print 'get session...'
fb.auth.getSession()
print 'add...'
try:
id_of_message = fb.stream.publish(message='my test message', uid=ID_OF_YOUR_PAGE)
except Exception, e:
error_code = None
try:
error_code = e.code
except AttributeError:
pass
if error_code:
print "Facebook returned an error - sorry! %s %s" % (str(e.code), repr(e))
else:
print "Facebook returned an error - sorry (no error code)! %s" % (repr(e))
else:
print id_of_message
And that’s all. Try to use it.
Sometimes it’s necessary to use request_extended_permission() (if we want to add privileges to our user), so you can uncomment these two lines.
Lots of hours… but at last – success.
Hello, I'm Karol Zielinski, internet evangelist, an entrepreneur, project manager and a web developer from Gdynia, Poland. I like creative design, good advertisement, social media and all kind of stuff around the web.
February 23, 2010, 5:46 am
[...] tech.karolzielinski.com Follow us on Twitter 35 śledzących RSS Feed 277 czytelników Publikowanie postów na Facebook Page walla 1 głosuj! Jak przy pomocy Facebook REST API publikować posty na wall'a [...]
February 24, 2010, 1:30 am
Hey, first of all nice Guide,
But I didn’t get it to work, When I do the step “Check everything” and set everything to the correct params I get the response
{“error_code”:200,”error_msg”:”User must have accepted TOS”,”request_args”:[………….
And I can’t figure out what I’ve done wrong.
Mvh Heppy.
February 24, 2010, 1:42 am
Nevermind, just saw that you created a new App page AND fan page,
And didn’t used the fan page that comes with the App.
Regards Heppy.
February 25, 2010, 12:59 am
Hey, this was really helpfull, I could not use that way to publish to a page wall so I used this insted:
http://stackoverflow.com/questions/2332315/pyfacebook-facebook-instance-has-no-stream-methods
Thanks for this post!
March 9, 2010, 4:43 pm
I’m so confused. I created the page, how do I create an app? Help Please!!!!
March 9, 2010, 11:11 pm
@yasmine
You need to tell something more. What would you like to do? What kind of app?
Start here: http://developers.facebook.com/get_started.php
March 15, 2010, 9:01 am
I’m getting “error_code”:200,”error_msg” instead of “result: 1″.
What should I do? And where should I post the script in python above?
Thanks,
Martin
March 15, 2010, 12:37 pm
@Martin
on http://wiki.developers.facebook.com/index.php/Stream.publish you have a list of error codes.
200 means “ermissions error. The application does not have permission to perform this action. “, so probably you need to add privileges to your app. Look above at the section “Add permissions to your app” and prepare your ‘special’ link.
March 15, 2010, 2:35 pm
I made it right. It showed me “1″.
However, as a complete noob, I can’t understand what should I do with the python code and how should I run it.
Martin
March 18, 2010, 2:05 am
Thank you Karol for your link to add proper permission related to Fan Pages !
March 18, 2010, 2:07 am
you’re welcome
March 19, 2010, 7:16 am
This works for publishing to Fan Pages, but not to the Application’s own wall.
April 3, 2010, 1:56 am
Hey! I didn’t need the python code (not my language) but your links for setting permissions helped a lot with a problem I was having for the last few hours
Thanks!
April 3, 2010, 8:12 pm
Just what I needed, thanks.
April 17, 2010, 4:47 am
Thanks Man, it worked and helped me a lot.
May 15, 2010, 7:56 pm
When I add permissons to my app, I got this error message:
===============================
API Error Code: 100
API Error Description: Invalid parameter
Error Message: When enabling the profile selector, an app may not request permissions that do not apply to all profiles in the selector. Note: You are seeing this message because you are a developer of this application. For regular users, inapplicable permissions are silently ignored.
===============================
Please Help!
May 19, 2010, 2:37 am
I face the same problem
API Error Code: 100
API Error Description: Invalid parameter
Error Message: When enabling the profile selector, an app may not request permissions that do not apply to all profiles in the selector. Note: You are seeing this message because you are a developer of this application. For regular users, inapplicable permissions are silently ignored.
May 24, 2010, 1:44 pm
If you remove the “offline_access” parameter from the request it seems to allow you through. Not sure if this helps but thought I would share.
June 11, 2010, 2:08 am
Hi,
Thanks for posting. It’s working and really helpful for me.
Thanks
June 14, 2010, 4:07 am
I`m posting messages via facebook api client to user`s wall and I need besides Like link there have Share link. in my permissions list is share_item and offline_access. Still i don`t get desired link for the publishing posts.
Did anyone impact with this problem?
Any suggestion will be appreciated!
June 15, 2010, 2:41 am
hello gang..
wonder if anyone can be of help since fb help does not exist nor covers this issue. I have seen others post similar problem
In process of assigning admin rights of account to another user and then revoking it, the admin rights to own page has vanished now. can’t post on own wall nor do other admin type functions.
Not sure how to reinstate those rights. Am sure it’s a fb tech matter but wonder if anyone has a helpful comment/hint..
TIA for any assistance on this.
June 25, 2010, 3:22 pm
Hey where does the python script go, I have no understanding of python
July 7, 2010, 1:18 am
Cool WEB
July 13, 2010, 7:01 am
Thanks! the special url for adding permissions to the page worked!!
July 15, 2010, 10:03 am
I keep seeing that applications come with fan pages, but… I don’t know where the fan page is to my application??? Can you offer any insight to this?
July 19, 2010, 9:18 am
I found this post looking for ways to post, as a page, to other pages or users accounts. I’m not creating an app, I just want to be able to respond to other users/pages comments about my page by posting responses as my page rather than myself… is that impossible?
July 30, 2010, 12:55 pm
Hello,
i’m trying to develop a application in c# by using facebook rest api (.NET api) and i’m trying to send a post my fan page name with fan page’s name,not my own name…
how can i do this,please help me
August 2, 2010, 3:24 pm
It’s not working.You are lie.I am cry.I am play Crysis for you.
August 5, 2010, 7:11 pm
i think this is what is being implemented now in the current facebook setting.
my concern is “how do i do it the other way around?” i want to post as a user/admin, not using the facebook page name.