Facebook Post链接到墙错误

时间:2012-10-25 05:18:10

标签: php facebook facebook-graph-api

我想在facebook墙上发布一个链接。但我收到了这些错误。请帮助我解决这个错误。

  $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)创建共享时发生错误

2 个答案:

答案 0 :(得分:1)

您可以尝试添加'type' => 'link'并查看它是否有效吗?据我在Facebook论坛上看到,这实际上是一个错误。

答案 1 :(得分:1)

你没有做错任何事,你的代码中有一个小的php错误,因为你的$ user_id变量没有被读取。 解决方案,在代码中用/$user_id/feed左右的双引号替换单引号。试试这个会起作用:

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