0

我正在尝试在 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) 创建共享时发生错误

4

2 回答 2

1

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

于 2012-10-25T05:25:47.503 回答
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'
                    )
            );
于 2012-10-25T07:12:39.643 回答