Is it possible to publish action from a Facebook Page?

。_饼干妹妹 提交于 2019-12-11 18:06:20

问题


I've been using the great facebook OpenGraph and the publish_actions permission. My users can publish actions through our website, and it's directly connected to there Facebook-Timeline. Great integration, very simple to be developped : thanks a lot for your work!

But, I have one more question :

Is it possible to use publish_actions not from a specific user but directly from a Facebook Page? (as described here for a user: https://developers.facebook.com/docs/opengraph/actions/#create)

For example, User John Smith has one Facebook Page (named "John Smith Advocate"), and wants to publish action, not from John Smith himself, but from the Facebook Page "John Smith Advocate".

I wonder if it's possible.

Thanks a lot guys !


回答1:


In order to publish as a page, you need to obtain an authentication token for that page. To do this you need to follow these steps (sorry for the lack of detail, hopefully this will point you in the right direction):

1) A user who is an administrator of your page needs to be authenticated with your app, and you need to get the "manage_pages" extended permission for them

2) get a list of all the accounts the user is an admin of: https://graph.facebook.com/me/accounts

3) you'll get a json array of pages the user is an admin of, and also an access token for each page - extract the relevant access token

4) Use the access token to post to the relevant album ID (owned by the page) - here is some php code that does it;

<?php
$args = array('message' => 'Caption');
$args['image'] = '/path/to/image.jpg';
$args['access_token'] = $page_access_token;

$data = $facebook->api('/'. $album_id . '/photos', 'post', $args);


来源:https://stackoverflow.com/questions/10213409/is-it-possible-to-publish-action-from-a-facebook-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!