FB Graph API发布到我的一个页面的墙上


FB Graph API posting to the wall of one of my pages

我不明白FB的API是否非常愚蠢,或者我的API感知不适合这个。我的目标很简单。我有一个内容管理系统。当我从CMS的管理页面创建新闻时,我也想将其发布到我的Facebook页面。这个 API 激怒了我!这是我的代码;

$s = FacebookSession::setDefaultApplication('appid', 'secret'); 
$session = FacebookSession::newAppSession();
// when I use belowed two line, I'm getting error
//$request = new FacebookRequest($session, 'GET', '/me'); 
//$pageList = $request->execute()->getGraphObject()->asArray(); 
$session = new FacebookSession('I don't know what to write here? I have a session already? When I use the access token which taken from api explorer page, due to it's life is short, I'm getting also error.'); 
$page_post=(new FacebookRequest( $session, 'POST','/<my_page_id_not_my_profile_id>/feed', array(
                    'access_token' => 'die!!! one more token! what is this!',
                    'link' => 'link',
                    'message' => 'message', ) ))->execute()->getGraphObject()->asArray();

注意:我不希望弹出窗口登录或任何其他方法。我只想要一个无辜的 API 像推特一样甜蜜地使用......

Facebook API的工作方式与Twitter非常相似。您也不能只在只有应用程序会话的情况下在Twitter上发帖,您需要授权用户。

由于Facebook上有用户个人资料和页面,因此有用户访问令牌和页面访问令牌。您需要的是一个页面访问令牌,您可以通过授权应用用户获取用户令牌并调用/me/accounts端点来获取您管理的所有主页的页面令牌来获得一个。此外,您需要授予用户publish_actionsmanage_pages权限。之后,您可以使用带有该页面令牌的/page-id/feed端点"作为页面"发布到您的页面墙。

以下是有关访问令牌的详细信息,具体需要的是永久存在的"扩展页面令牌":

  • https://developers.facebook.com/docs/facebook-login/access-tokens
  • http://www.devils-heaven.com/facebook-access-tokens/