在页面时间轴上发布的Facebook消息

时间:2015-07-02 07:38:11

标签: php facebook facebook-graph-api

我想在Facebook页面时间轴上显示帖子文字/留言。但是没有出现在Facebook页面时间轴上。它出现在通知部分。 代码运行成功,我得到200响应(意味着文本/消息在Facebook页面上成功发布)。我正在使用最新的Facebook API版本2.3。

源代码

<?php
session_start();
// added in v4.0.0
require_once 'autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;

// init app with app id and secret
FacebookSession::setDefaultApplication( 'xxxxxxxxxxxxx','xxxxxxxxxxxxxxxx' );
// login helper with redirect_uri
    $helper = new FacebookRedirectLoginHelper('http://localhost:8080/facebook_Login_Version_4/fbconfig.php' );
try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
  // graph api request for user data
  $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();

        $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
        $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
        $femail = $graphObject->getProperty('email');    // To Get Facebook email ID
    /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
        $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $femail;
    /* ---- header location after session ----*/

    //Facebook Posting section---------------
    if($session) {
  try {
    $pageid = XXXXXXXXXXXXXXXXXXXX;
    $response = (new FacebookRequest(
      $session, 'POST', '/$pageid/feed', array(
        'message' => 'text post on page!!'
      )
    ))->execute()->getGraphObject();

    echo "Posted with id: " . $response->getProperty('id');
  } catch(FacebookRequestException $e) {
    echo "Exception occured, code: " . $e->getCode();
    echo " with message: " . $e->getMessage();
  }   
}
  header("Location: index.php");
} else {
  $loginUrl = $helper->getLoginUrl();
 header("Location: ".$loginUrl);
}
?>

以上源代码

$pageid = XXXXXXXXXXXXXXXXXXXX;
$response = (new FacebookRequest(
  $session, 'POST', '/$pageid/feed', array(
    'message' => 'text post on page!!'
  )
))->execute()->getGraphObject();

这是facebook发布的主要部分。

附上发布的内容enter image description here

您可以在通知区域看到发布的消息。我很惊讶为什么这个帖子显示在通知部分。我需要在页面时间轴上发布消息。

是否有任何其他API可用于页面时间线发布或Facebook页面上的任何设置,以便在时间轴上显示我发布的消息。

帮助表示赞赏。

由于

0 个答案:

没有答案
相关问题