简体   繁体   中英

Post to a Facebook page (not user page) using Koala

How do I post to a user page using Koala? I don't want to post to a Users' wall, but to a User page (a user can manage many pages).

The code I have right now is this:

facebook_graph = Koala::Facebook::GraphAPI.new(self.token)
facebook_graph.put_wall_post(message)

And I know you can do this

facebook_graph.put_wall_post(message, profile_id="page.id")

Where self.token is already in the scope of manage_pages , but I don't even think that is necessary. So, how would you post to a particular page of a user which I have the access token using Koala? How do I discover the pages that a particular user has, and their correspondent ids?

Taken from the Koala README, this will post to a users wall:

@graph.put_object("me", "feed", :message => "I am writing on my wall!")

So, the following will post to the Wall of a page (in your context):

graph = Koala::Facebook::GraphAPI.new(self.token)
graph.put_object(page.id, "feed", :message => "I am writing on a page wall!")

Ensure, that the token you use is a user token (if you want to post as a user) or a page token if you want to post as the page itself.

More to read about Graph(Page): http://developers.facebook.com/docs/reference/api/page/

and Koala: https://github.com/arsduo/koala

EDIT: due to comment

To get Pages of a user

@graph.get_connections("me", "accounts")

Documentation: http://developers.facebook.com/docs/reference/api/user/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM