简体   繁体   English

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

[英]FB Graph API posting to the wall of one of my pages

I don't understand whether FB' API is very silly or my API perception is not suitable for this. 我不明白FB'API是否非常愚蠢,或者我的API感知不适合这样做。 My goal is very simple. 我的目标很简单。 I have a CMS. 我有一个CMS。 When I create a news from my admin page of the CMS, also I want to post it to my facebook page. 当我从CMS的管理页面创建新闻时,我也想将其发布到我的Facebook页面。 This API irritating me! 这个API惹恼了我! Here is my code; 这是我的代码;

$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();

NOTE: I don't want pop-ups to login or anyother method. 注意:我不希望弹出窗口登录或任何其他方法。 I want just a innocent API to use sweetly like twitter's... 我只希望一个纯真的API像Twitter的一样甜蜜地使用...

The Facebook API works very similar to Twitter. Facebook API的工作原理与Twitter非常相似。 You can´t just post on Twitter with only an App Session either, you need to authorize a User. 您也不能仅在Twitter上仅发布一个应用会话,还需要授权用户。

Since there are User Profiles And Pages on Facebook, there are User Access Tokens and Page Access Tokens. 由于Facebook上有用户个人资料和页面,因此有用户访问令牌和页面访问令牌。 What you need is a Page Access Token and you get one by authorizing a User with your App to get a User Token and calling the /me/accounts endpoint to get Page Tokens for all the Pages you manage. 您需要的是页面访问令牌,然后通过授权用户使用您的应用程序来获取用户令牌并调用/me/accounts端点以获取您管理的所有页面的页面令牌,从而获得一个页面访问令牌。 Also, you need to authorize the User with the publish_actions and manage_pages permissions. 另外,您需要使用publish_actionsmanage_pages权限授权用户。 After that, you can use the /page-id/feed endpoint with that Page Token to post to your Page Wall "as Page". 之后,您可以使用带有该页面令牌的/page-id/feed终结点“作为页面”发布到页面墙。

Here´s more information about Access Tokens, what you need specifically is an "Extended Page Token" that lasts forever: 这是有关访问令牌的更多信息,您需要的是永久存在的“扩展页面令牌”:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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