Facebook認証をphp Webサイトに統合しようとしています。
以下のコードを使用しました:
<?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が必要です」というエラーが発生するまで、同様の問題に直面していると思いますが、その質問に対する受け入れられた回答はありません。
何か不足している場合は提案してください。