... because from time to time I'm a web developer, too
About me
Projects
Contact
Links

Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API)

February 23, 2010 | python, tools
author: Karol Zielinski | comments: 29 | views: 8736
Tags: , , , ,

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).

Facebook

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.

Add app to your fan page.

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.

Set application type

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.

Add permissions to your app

Prepare special link:

http://www.facebook.com/connect/prompt_permissions.php?api_key=YOUR_API_KEY&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=ID_OF_YOUR_PAGE

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’.

Check everything

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.

Write a code

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.

Bookmark and Share
Post Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API) to develway Post Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API) to Delicious Post Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API) to Digg Post Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API) to Facebook Post Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API) to Reddit Post Publish post on Facebook Page wall as a Page (not a user) (python + Facebook REST API) to StumbleUpon

Related news and resources

Comments (29)

4Avatars v0.3.1 v0.3.1
Publikowanie postów na Facebook Page walla - develway.pl
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 [...]

4Avatars v0.3.1 v0.3.1
Heppy
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.

4Avatars v0.3.1 v0.3.1
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.

4Avatars v0.3.1 v0.3.1
Pablo Rosales
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!

4Avatars v0.3.1 v0.3.1
yasmine
March 9, 2010, 4:43 pm

I’m so confused. I created the page, how do I create an app? Help Please!!!!

4Avatars v0.3.1 v0.3.1
Karol Zielinski
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

4Avatars v0.3.1 v0.3.1
Martin Metodiev
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

4Avatars v0.3.1 v0.3.1
Karol Zielinski
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.

4Avatars v0.3.1 v0.3.1
Martin Metodiev
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

4Avatars v0.3.1 v0.3.1
Jakub Zygmunt
March 18, 2010, 2:05 am

Thank you Karol for your link to add proper permission related to Fan Pages !

4Avatars v0.3.1 v0.3.1
Karol Zielinski
March 18, 2010, 2:07 am

you’re welcome :)

4Avatars v0.3.1 v0.3.1
Otto
March 19, 2010, 7:16 am

This works for publishing to Fan Pages, but not to the Application’s own wall.

4Avatars v0.3.1 v0.3.1
Clint
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!

4Avatars v0.3.1 v0.3.1
muybay
April 3, 2010, 8:12 pm

Just what I needed, thanks.

4Avatars v0.3.1 v0.3.1
Ashish Jain
April 17, 2010, 4:47 am

Thanks Man, it worked and helped me a lot.

4Avatars v0.3.1 v0.3.1
claire
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!

4Avatars v0.3.1 v0.3.1
CG
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.

4Avatars v0.3.1 v0.3.1
Bryan C.
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.

4Avatars v0.3.1 v0.3.1
posoft
June 11, 2010, 2:08 am

Hi,
Thanks for posting. It’s working and really helpful for me.
Thanks

4Avatars v0.3.1 v0.3.1
Natali
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!

4Avatars v0.3.1 v0.3.1
Sara
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.

4Avatars v0.3.1 v0.3.1
Flying_machine
June 25, 2010, 3:22 pm

Hey where does the python script go, I have no understanding of python

4Avatars v0.3.1 v0.3.1
Lubelski katalog firm
July 7, 2010, 1:18 am

Cool WEB ;)

4Avatars v0.3.1 v0.3.1
Anurag
July 13, 2010, 7:01 am

Thanks! the special url for adding permissions to the page worked!!

4Avatars v0.3.1 v0.3.1
Jeff
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?

4Avatars v0.3.1 v0.3.1
Mel
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?

4Avatars v0.3.1 v0.3.1
lastarabos
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 :(

4Avatars v0.3.1 v0.3.1
Mark Zuckenberg
August 2, 2010, 3:24 pm

It’s not working.You are lie.I am cry.I am play Crysis for you.

4Avatars v0.3.1 v0.3.1
phraensys
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.

Write a comment

Karol Zielinski :: Just a tech stuff 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.

Most popular posts

Much more links

Karol Zielinski    |   contact me
Gdynia, Poland
RSS - Just a tech stuff - python, java blog - web development blog Karol Zielinski on twitter Karol Zielinski on LinkedIn Karol Zielinski on facebook Karol Zielinski on delicious Karol Zielinski on digg Karol Zielinski on flickr Karol Zielinski on stumbleupon Karol Zielinski on technorati