简体   繁体   中英

Facebook Post link to wall error

I am trying to post a link on the facebook wall. but i got these error. please help me anyone to solve this error.

  $config = array(
   'appId' => 'xxxxxxxxxxxxx',
   'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

  );  


  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
   $facebook = new Facebook($config);
   $user_id = $facebook->getUser();
 if($user_id) {

  try {
   $facebook->api('/$user_id/feed','POST',
               array(  'access_token' => $facebook->getAccessToken(),
                 'message' => 'Hello World!',
                 'link' => 'www.example.com'
                    )
            );
} catch(FacebookApiException $e) {
$result = $e->getResult();
 error_log(json_encode($result));


    $login_url = $facebook->getLoginUrl( array(
                   'scope' => 'publish_stream'
                   )); 
    echo 'Please <a href="' . $login_url . '">login.</a>';
    error_log($e->getType());
    error_log($e->getMessage());
  }   

  echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
} else {

  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>';

} 

{"error":{"message":"(#1) An error occured while creating the share","type":"OAuthException","code":1}}

OAuthException

(#1) An error occured while creating the share {"error":{"message":"(#1) An error occured while creating the share","type":"OAuthException","code":1}}

OAuthException (#1) An error occured while creating the share

Could you try to add 'type' => 'link' and see if it works? As far as I've read on Facebook forums this is actually a bug.

you are not doing anything wrong, there is a small php mistake in your code due to which your $user_id variable is not being read. solution,replace single quote with double quote around /$user_id/feed in your code. try this it will work:

$facebook->api("/$user_id/feed",'POST',
               array(  'access_token' => $facebook->getAccessToken(),
                 'message' => 'Hello World!',
                 'link' => 'www.example.com'
                    )
            );

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