Reputation: 33
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
Upvotes: 0
Views: 1235
Reputation: 4634
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'
)
);
Upvotes: 1
Reputation: 520
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.
Upvotes: 1