以用户身份发布到FB页面


Post to FB Page as User

所以我有一个Facebook页面(我们称之为X),上面有应用程序Y。用户可以通过Y提问,它会作为用户(而不是应用程序)发布到X。

我对该应用程序的权限当前设置为publish_stream。

我可以通过获取代币

    $token_url = "https://graph.facebook.com/oauth/access_token?" .
       "client_id=" . $this -> data["environment"] -> fb_appid .
       "&client_secret=" . $this -> data["environment"] -> fb_appsecret .
       "&grant_type=client_credentials";
    $app_token = file_get_contents($token_url);

这给了我一个很好的象征。

现在,如果我尝试通过APi调用POST,我会得到两个结果:

当我不通过令牌并简单地调用时

$post_id = $this ->Facebook->fb_api("/PAGE_ID/feed", "POST", array("message"=>"This is a post from PHP."));

我得到了JSON 形式的回复

{
   "id": "PAGEID_someOtherID"
}

但是我没有看到墙上的柱子。

当我通过访问令牌时,ala

$post_id = $this ->Facebook->fb_api("/PAGE_ID/feed", "POST", array("access_token"=>$app_token,"message"=>"This is a post from PHP."));

我的回答是空的。

这么简单的概念我做错了什么?

来自Facebook文档的示例https://developers.facebook.com/docs/reference/php/facebook-api/

<?php
      // Remember to copy files from the SDK's src/ directory to a
      // directory in your application on the server, such as php-sdk/
      require_once('php-sdk/facebook.php');
      $config = array(
        'appId' => 'YOUR_APP_ID',
        'secret' => 'YOUR_APP_SECRET',
      );
      $facebook = new Facebook($config);
      $user_id = $facebook->getUser();
    ?>
    <html>
      <head></head>
      <body>
      <?
        if($user_id) {
          // We have a user ID, so probably a logged in user.
          // If not, we'll get an exception, which we handle below.
          try {
            $ret_obj = $facebook->api('/'.$pageid.'/feed', 'POST',
                                        array(
                                          'link' => 'www.example.com',
                                          'message' => 'Posting with the PHP SDK!'
                                     ));
            echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
          } catch(FacebookApiException $e) {
            // If the user is logged out, you can have a 
            // user ID even though the access token is invalid.
            // In this case, we'll get an exception, so we'll
            // just ask the user to login again here.
            $login_url = $facebook->getLoginUrl( array(
                           'scope' => 'publish_stream'
                           )); 
            echo 'Please <a href="' . $login_url . '">login.</a>';
            error_log($e->getType());
            error_log($e->getMessage());
          }   
          // Give the user a logout link 
          echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
        } else {
          // No user, so print a link for the user to login
          // To post to a user's wall, we need publish_stream permission
          // We'll use the current URL as the redirect_uri, so we don't
          // need to specify it here.
          $login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
          echo 'Please <a href="' . $login_url . '">login.</a>';
        } 
      ?>      
      </body> 
    </html>  

好吧,你不能在没有access_token的情况下在页面墙上发布一些东西,因为没有访问令牌,facebook无法实现谁是想要发布的用户&大约在你试图通过access_token发布的时候,我认为你做错了什么,请检查你的权限(你需要publish_stream而不是stream_publish),我很快会给你放一个示例代码