php Facebook : 您尚未登录: 您尚未登录。请登录并重试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40122570/
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
Facebook : You are not logged in: You are not logged in. Please log in and try again
提问by scriptkiddie
code throws error
代码抛出错误
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl("https://apps.facebook.com/{$appname}/", $permissions);
echo "<script>window.top.location.href='".$loginUrl."'</script>";
Error
错误
You are not logged in: You are not logged in. Please log in and try again.
您尚未登录:您尚未登录。请登录并重试。
the url which throws the error is (replaced my appname with appname) :
引发错误的 url 是(用 appname 替换了我的 appname):
full script
完整脚本
<?php
require_once '../../Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => "$appid",
'app_secret' => "$appsecret",
'default_graph_version' => 'v2.7',
]);
$helper = $fb->getCanvasHelper();
$permissions = ['email']; // optionnal
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
$accessToken = (string) $accessToken;
$fb->setDefaultAccessToken($accessToken);
if (isset($_GET['code'])) {
header('Location: ./');
}
// validating the access token
try {
$request = $fb->get('/me');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
if ($e->getCode() == 190) {
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl("https://apps.facebook.com/{$appname}/", $permissions);
echo "<script>window.top.location.href='".$loginUrl."'</script>";
exit;
}
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// getting basic info about user
try {
$profile_request = $fb->get('/me?fields=name,first_name,last_name,email');
$user_profile = $profile_request->getGraphNode()->asArray();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
$url = "https://apps.facebook.com/{$appname}/";
echo '<script>window.top.location.href='.$url.'</script>';
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// priting basic info about user on the screen
//print_r($user_profile);
// Now you can redirect to another page and use the access token from $_SESSION['facebook_access_token']
} else {
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl("https://apps.facebook.com/{$appname}/", $permissions);
echo "<script>window.top.location.href='".$loginUrl."'</script>";
}
回答by scriptkiddie
This error was thrown because I have not added my app's canvas url(example https://apps.facebook.com/appname/) in
被抛出这个错误,因为我没有加入我的应用程序的画布网址(例如https://apps.facebook.com/appname/中)
Facebook Login->settings under Valid OAuth redirect URIs
Facebook 登录-> 有效 OAuth 重定向 URI 下的设置
回答by Fernando Wolff
You have to setup the permissions to the desired URL's on the following sections of the API:
您必须在 API 的以下部分设置所需 URL 的权限:
- Products -> Facebook Logins -> Configurations -> OAuth URi's
- On Configurations > Basic, set your site URL
- On Configurations > Advanced , set a list of allowed URI's for share redirecting.
- 产品 -> Facebook 登录 -> 配置 -> OAuth URI's
- 在“配置”>“基本”上,设置您的站点 URL
- 在 Configurations > Advanced 上,设置允许共享重定向的 URI 列表。
回答by Kakashi
I have same alert when I try test login facebook with localhost. Then I add http://localhost:3000to Valid OAuth redirect URIs and try test again. This worked for me. Thank you @Harkirat Saluja
当我尝试使用本地主机测试登录 facebook 时,我有同样的警报。然后我将http://localhost:3000添加到有效的 OAuth 重定向 URI 并再次尝试测试。这对我有用。谢谢@Harkirat Saluja
回答by Marcos Curvello
If you intend is testing the app in a staging environment, leave the iPhone Store ID field blank and it will allow you to save the current platform and test.
如果您打算在暂存环境中测试应用程序,请将 iPhone Store ID 字段留空,这样您就可以保存当前平台并进行测试。
回答by Triston
The simple FIXfor the Facebook : You are not logged in: You are not logged in. Please log in and try again
Facebook的简单修复:您尚未登录:您尚未登录。请登录并重试
TURN OFF Client OAuth Login Enables the standard OAuth client token flow. Secure your application and prevent abuse by locking down which token redirect URIs are allowed with the options below. Disable globally if not used
关闭客户端 OAuth 登录 启用标准 OAuth 客户端令牌流。通过使用以下选项锁定允许的令牌重定向 URI,保护您的应用程序并防止滥用。如果不使用则全局禁用
This the the TOP button under your app settings.
这是您的应用程序设置下的顶部按钮。
Hope this helps
希望这可以帮助