0

我正在创建一个 Facebook 应用程序。我正在尝试发布用户墙。但我没有得到任何回应

php代码

 $user = $facebook->getUser(); 

if($user == 0) {



$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));

echo ("<script> top.location.href='".$login_url."'</script>");

} else { $token=$facebook->getAccessToken();

  try {     
  params = array(

            'message'       =>  "Hurray! This works :)",
            'name'          =>  "This is my title",
            'caption'       =>  "My Caption",
            'description'   =>  "Some Description...",
            'link'          =>  "http://stackoverflow.com",
            'picture'       =>  "http://i.imgur.com/VUBz8.png",
        );

        $post = $facebook->api("/me/feed","POST",$params);


  }
   catch (FacebookApiException $e) {
      $result = $e->getResult();
     }

  }

我无法将内容发布到用户的墙上。请帮助我调试代码

4

2 回答 2

0

尝试使用 php curl 发布。如果使用 rest api 工作你的 facebook 类。Rest api最近被删除。

$user = $facebook->getUser(); 

if($user == 0) {



$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));

echo ("<script> top.location.href='".$login_url."'</script>");

} else { $token=$facebook->getAccessToken();

  try {     
  $params = array(
            'access_token'  => $token,
            'message'       =>  "Hurray! This works :)",
            'name'          =>  "This is my title",
            'caption'       =>  "My Caption",
            'description'   =>  "Some Description...",
            'link'          =>  "http://stackoverflow.com",
            'picture'       =>  "http://i.imgur.com/VUBz8.png",
        );

$url = 'https://graph.facebook.com/'.$user.'/feed';
    $ch = curl_init();
    curl_setopt_array($ch, array(
                CURLOPT_URL => $url,
                CURLOPT_POSTFIELDS => $params,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_VERBOSE => true
            ));
              $result = curl_exec($ch);
              print_r($result);
              curl_close($ch);

  }
   catch (FacebookApiException $e) {
      $result = $e->getResult();
     }

  }

在您的代码中,params 不是 $params。

于 2012-09-09T20:19:03.053 回答
0

试试这个,我使用以下方法在我的 FB 上成功发布:

$user = $facebook->getUser(); 

if($user == 0) {

//$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));

//echo ("<script> top.location.href='".$login_url."'</script>");

} else { $token=$facebook->getAccessToken();

  try {     
        $post = $facebook->api("/me/feed","POST",array(

            'message'       =>  "Hurray! This works :)",
            'name'          =>  "This is my title",
            'caption'       =>  "My Caption",
            'description'   =>  "Some Description...",
            'link'          =>  "http://stackoverflow.com",
            'picture'       =>  "http://i.imgur.com/VUBz8.png"
        ));
  }
   catch (FacebookApiException $e) {
      $result = $e->getResult();
     }
  }

如果您还没有,请记住包含 facebook.php api 和您的代码类初始化

$facebook = new Facebook(array(
                                'appId' => APP_ID,
                                'secret' => APP_SECRET,
                                'cookie' => true
                            ));
于 2012-09-09T19:23:49.337 回答