简体   繁体   中英

Facebook post as page to user wall

Okay I can't figure out what the problem here is... I am trying to post to a user wall as a page. I keep getting string(53) "(#200) The target user has not authorized this action" here is the complete code

       session_start();
      $config = array();
      $config['appId'] = 'xxxxxxxxx';
      $config['secret'] = 'xxxxxxxx';
      $config['fileUpload'] = false; // optional
      $facebook = new Facebook($config);

        $params = array(
          'scope' => 'user_birthday, user_likes, publish_actions, email, publish_stream, manage_pages',
          'redirect_uri' => 'xxxxxxxxxxxxx'
        );

        $loginUrl = $facebook->getLoginUrl($params);
        $logoutUrl = $facebook->getLogoutUrl();
        $user_id = $facebook->getUser();
    ?>
    <html>
      <head></head>
      <body>

      <?
        if($user_id) {
          try {
            echo 'Please <a href="' . $logoutUrl . '">logout.</a>';
            $user_profile = $facebook->api('/me','GET');
            echo "Name: " . $user_profile['name'];
            $access_token = $facebook->getAccessToken();
            $page_id = 'xxxxxxxxxx';
            $result = $facebook->api("/me/accounts");
            foreach($result["data"] as $page) {
                if($page["id"] == $page_id) {
                    $page_access_token = $page["access_token"];
                    break;
                }
            }
            if( !empty($page_access_token) ) {
                $args = array(
                    'access_token'  => $page_access_token,
                    'message'       => "Hello Billy!!"
                );
                $post_id = $facebook->api("/{$user_profile['id']}/feed","post",$args);

            } else {
            }

    //        $page = $facebook->api("/{$page_id}",'GET');


          } catch(FacebookApiException $e) {
            error_log($e->getType());
            error_log($e->getMessage());
            ?><pre><?var_dump($e->getMessage())?></pre><?
          }   
        } else {
    ///
          echo 'Please <a href="' . $loginUrl . '">login.</a>';

        }

      ?>

      </body>
    </html>

Just to confirm, you're trying to post to a user's profile or timeline, and have the post appear with a Page as the sender?

That's not possible and never has been. The API simply doesn't support it.

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