简体   繁体   English

Facebook的PHP SDK无法正常工作

[英]facebook php sdk not working

i used two codes and its not working the first one : 我使用了两个代码,第一个代码不起作用:

    <?php
  require_once('fb/facebook.php');
  $config = array(
    'appId' => 'xxxxx',
    'secret' => 'xxxxx',
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>
<html>
  <head></head>
  <body>

  <?php
      function render_login($facebook) {
          $canvas_page = 'http://fbbost.eb2a.com/';
          // HERE YOU ASK THE USER TO ACCEPT YOUR APP AND SPECIFY THE PERMISSIONS NEEDED BY
          $login_url = $facebook->getLoginUrl(array('scope'=>'email,user_photos,friends_photos', 'redirect_uri'=>$canvas_page));
          echo 'Please <a href="' . $login_url . '">login.</a>';
      }

    if($user_id) {
      try {

        $user_profile = $facebook->api('/me','GET');
        echo "Name: " . $user_profile['name'];

      } catch(FacebookApiException $e) {
        render_login($facebook);
        echo "1";
        error_log($e->getType());
        error_log($e->getMessage());
      }
    } else {
       render_login($facebook);
       echo "2";
    }
  ?>

  </body>
    </html>

and the second one : 第二个:

<html>
<head>
<title>NNN</title>
</head>
<body>
<?php
include "fb/facebook.php";
$facebook=new Facebook(array(
  'appId' => 'xxxxx',
  'secret' => 'xxxxx',
  'cookie' => true
));

$session=$facebook->getUser();
$me=null;

if($session){
  try{
    $me=$facbook->api('/me');
    print_r($me);
  }
  catch (FacebookApiException $e){
    echo $e->getMessage();
  }
}

if($me){
  $logoutUrl=$facbook->getLogoutUrl();
  echo "<a href='$logoutUrl'>Logout</a>";
}
else{
  $loginUrl=$facebook->getLoginUrl(array(
    'scope' => 'publish_stream,read_friendlists'
  ));
  echo "<a href='$loginUrl'>Login</a>";
}

?>
</body>
</html>

both codes return the same error when i login : App Not Setup: The developers of this app have not set up this app properly for Facebook Login. 我登录时,两个代码均返回相同的错误:应用未设置:此应用的开发人员尚未针对Facebook登录正确设置此应用。

I think your app is not public. 我认为您的应用不是公开的。 You need to set it to public to use it with any Facebook account other than the developer's own account. 您需要将其设置为公开,才能与开发者自己的帐户以外的任何Facebook帐户一起使用。 Go to "Status and Review" and make the app public. 转到“状态和评论”,并将应用公开。

Besides, check that you have properly setup the app domain. 此外,请检查您是否已正确设置应用程序域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM