好的,正如标题所示,我一直在尝试让 Facebook 的 OAuth 在我的 localhost/ 上运行,我一直在努力解决各种问题,但我只是不知道我的最新问题是什么,即页面加载,并且如果用户已登录,它会显示注销 URL 和 UID . 长话短说,我似乎无法让在我的本地主机中运行的网站将我从 Facebook 和我的网站上注销!任何想法都会有很大的帮助。这是我的代码
<?php
session_start();
// store session data
include "src/facebook.php";
$facebook = new Facebook(Array(
"appId" => "xxx",
"secret" => "xxx"
));
$user = $facebook->getUser();
echo "UID: " . $user . "<br/>";
// THIS WAS MY FIRST TRY WHICH DIDNT SUCCEED
// if ($user) {
// $logoutUrl = $facebook->getLogoutUrl();
// echo "<a href='" . $logoutUrl . "'>Logout</a>";
// } else {
// $loginUrl = $facebook->getLoginUrl();
// echo "<a href='" . $loginUrl . "'>Login</a>";
// }
// WITH THE ABOVE CODE I GET:
// An error occurred with PHP-SDK. Please try again later.
// API Error Code: 191
// API Error Description: The specified URL is not owned by the application
// Error Message: Invalid redirect_uri: Given URL is not allowed by the Application configuration.
// THIS WAS MY SECOND TRY AFTER SEARCHING FOR INFO,
// ALL I DID WAS MANUALLY ADD THE
// REDIRECT URI AND ADDED ? , THE REASON IS IF I DIDN'T ADD IT,
// IT WOULD GIVE ME AN CSRF ERROR
// STATING THAT THE STATE VALUE IS NOT CORRECT, I SEARCHED FOR THE SOLUTION
// FOR THAT PROBLEM WITH NO LUCK SO I TRIED THIS
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
echo "<a href='" . $logoutUrl . "'>Logout</a>";
} else {
$loginUrl = $facebook->getLoginUrl(Array(
"redirect_uri" => "http://localhost/php-sdk/index.php?"
));
echo "<a href='" . $loginUrl . "'>Login</a>";
}
// WITH THE ABOVE CODE I NOW GET A UID AND THE LOGOUT URL DOES APPEAR, BUT ONCE I CLICK IT
// THE USER IS LOGGED OUT LIKE HE SHOULD BUT THEN ON REDIRECT OR RELOAD THE UID STILL
// APPEARS AND SO DOES THE LOGOUT LINK, EVEN THOUGH THE USER IS NOT LOGGED IN!!
?>