简体   繁体   中英

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. My goal is very simple. I have a CMS. When I create a news from my admin page of the CMS, also I want to post it to my facebook page. This API irritating me! 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...

The Facebook API works very similar to Twitter. You can´t just post on Twitter with only an App Session either, you need to authorize a User.

Since there are User Profiles And Pages on Facebook, there are User Access Tokens and Page Access Tokens. 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. Also, you need to authorize the User with the publish_actions and manage_pages permissions. After that, you can use the /page-id/feed endpoint with that Page Token to post to your Page Wall "as Page".

Here´s more information about Access Tokens, what you need specifically is an "Extended Page Token" that lasts forever:

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