我正在尝试将 facebook 身份验证集成到 php 网站中。
我使用了以下代码:
<?php
require '../facebook-php-sdk-master/src/facebook.php';
$app_id = 'some app id';
$app_secret = 'some secret';
$app_url = 'http://localhost/some app/';
$scope = 'email,publish_actions';
// Init the Facebook SDK
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
// Get the current user
$user = $facebook->getUser();
// If the user has not installed the app, redirect them to the Login Dialog
if ($user <> '0' && $user <> '') { /*if valid user id i.e. neither 0 nor blank nor null*/
try {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => $scope,
'redirect_uri' => $app_url,
));
die('<script>top.location.href="'.$facebook->getLoginUrl($params).'";</script>');
}
catch (FacebookApiException $e) { /*sometimes it shows user id even if user in not logged in and it results in Oauth exception. In this case we will set it back to 0.*/
error_log($e);
$user = '0';
}
}
else
{
echo 'user not found';
}
?>
问题是:
尽管我指定并使用了正确的应用程序 ID,但我总是收到此错误消息- 参数 app_id 是必需的。
我想我面临着类似的问题——直到在 Facebook API 登录上出现“需要参数 app_id”错误,但该问题没有被接受的答案。
请建议我是否遗漏任何东西。