php Facebook API 显示“需要参数 app_id”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22127830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:41:01  来源:igfitidea点击:

Facebook API showing "The parameter app_id is required"

phpfacebook-php-sdk

提问by Muhammad Ali

I have written correct AppID and APP secret but when I am running it on browser, Facebook is saying "The parameter app_id is required"

我写了正确的 AppID 和 APP 密码,但是当我在浏览器上运行它时,Facebook 说“需要参数 app_id”

is there any error in this code, or I have missed some information ? here is the link www.smmstest.base.pk/

这段代码是否有任何错误,或者我错过了一些信息?这是链接 www.smmstest.base.pk/

<?php 
require 'libs/facebook.php';
$facebook = new Facebook(array(
'appID' => '********************',
'secret' => '*************************',
'cookie' => true
));
   $user = $facebook->getUser();

   if ($user)
   {
      try
      {
         $user_profile = $facebook->api("/me");
      }
      catch (FacebookApiException $e)
      {
         error_log($e);
         $user = null;
      }      
   }

   if ($user)
   {
      $logoutUrl = $facebook->getLogoutUrl();
   }
   else
   {
      $loginUrl = $facebook->getLoginUrl();
   }
   ?>


<!doctype>
<html>
<head>
   <title>Fan page login</title>
</head>



   <body>

   <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>

        <a href="<?php echo $statusUrl; ?>">Check the login status</a>
      </div>
      <div>
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>

</body>

</html>

采纳答案by luschn

https://github.com/facebook/facebook-php-sdk

https://github.com/facebook/facebook-php-sdk

require 'facebook-php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
));

Make sure you use the code from the latest PHP SDK. If you write "appId" correctly, it will add the parameter to every call to the Facebook Servers (which is "app_id" internally).

确保使用来自最新 PHP SDK 的代码。如果您正确编写了“appId”,它会将参数添加到对 Facebook 服务器的每次调用中(内部为“app_id”)。

回答by Hong Janet

fix it as

将其修复为

require 'libs/facebook.php';
$facebook = new Facebook(array(
'appID' => '********************',
'secret' => '*************************',
'cookie' => true

appID change to appId, it should work

appID 更改为 appId,它应该可以工作