在Facebook墙上发布消息

时间:2013-02-11 10:09:56

标签: php facebook facebook-wall

我在facebook上创建了一个应用程序。现在我想在Facebook墙上发布消息。因为我是应用程序的开发人员,当我登录到我的Facebook帐户时,消息即将出现在我的墙上,但当我登录另一个用户时,此应用程序未获取并且页面正在重定向到 http://www.facebook.com/4oh4.php 。我的代码在下面给出

$facebook = new Facebook(array(

            'appId' => myAppId,
            'secret' => myAppSecret,
                'cookie' => true,
                'req_perms' => 'email,read_stream,read_friendlists,publish_stream,offline_access,manage_pages'

        ));
    $user = $facebook->getUser();
$app_id = myAppId;
        $canvas_page = "https://apps.facebook.com/apptestingas/";
        $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=email,read_stream,read_friendlists,publish_stream,offline_access,manage_pages";
 if(isset($_REQUEST["signed_request"]))
     {
        $signed_request = $_REQUEST["signed_request"];
        list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
        $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

     }
      if (empty($data["user_id"]))
     {
        echo("<script> top.location.href='" . $auth_url . "'</script>");

     }
     else 
     {
        $uid = $data["user_id"];

     } 
try {
    // Proceed knowing you have a logged in user who's authenticated.
 echo $token = $facebook->getAccessToken();
$user_profile = $facebook->api('/'.$uid.'',array (
'access_token' => $token)
);


  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
  if (!empty($user_profile )) {
        # User info ok? Let's print it (Here we will be adding the login and registering routines)

       echo  $username = $user_profile['name'];
    $uid = $user_profile['id'];
$facebook->api('/'.$uid.'/feed', 'post', array(
          'message' => "sdsgdg testingbbbb",

      ));
  }

请任何一个帮助

1 个答案:

答案 0 :(得分:1)

您的应用程序是否设置为沙盒模式?这在应用程序设置中是可控的。 引用说明:“如果启用,只有应用开发者才能使用应用”。