0

我想在我的 Facebook 用户帐户墙上发布一些测试墙帖子(不是任何 Facebook 页面或 Facebook 应用程序,只是普通用户帐户)。我尝试了像下面这样的 Facebook SDK,但什么也没发生,它只是要求我登录。但我想以编程方式登录,请告诉我如何做到这一点并发布到我自己的墙上?

require_once "API_Library/Facebook/src/facebook.php";
$config = array(
         'userId' => 'USER_ID',
     );

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

if($user_id)
             {

                 // We have a user ID, so probably a logged in user.
                 // If not, we'll get an exception, which we handle below.
                 try
                 {
                     $user = $config['userId'];
                     $user_profile = $facebook->api('/me', 'GET');
                     echo "Name: " . $user_profile['name'];
                     $ret_obj = $facebook->api('/me/feed', 'GET', array(
                         'link' => "https://www.facebook.com/$user",
                         'message' => 'Posting with the PHP SDK!'
                             ));
                     echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
                 }
                 catch(FacebookApiException $e)
                 {
                     $login_url = $facebook->getLoginUrl();
                     echo 'Please <a href="' . $login_url . '">login.</a>';
                     error_log($e->getType());
                     error_log($e->getMessage());
                 }
             }
             else
             {

                 // No user, print a link for the user to login
                 $login_url = $facebook->getLoginUrl();
                 echo 'Please <a href="' . $login_url . '">login.</a>';
             }
4

1 回答 1

1

您正在执行 HTTP GET 而不是 HTTP POST

$ret_obj = $facebook->api('/me/feed', 'GET', array(
                     'link' => "https://www.facebook.com/$user",
                     'message' => 'Posting with the PHP SDK!'
                         ));

您可能希望将 API 方法更改为POST

于 2012-09-17T16:59:36.640 回答