繁体   English   中英

Facebook:您尚未登录:您尚未登录。请登录并重试

[英]Facebook : You are not logged in: You are not logged in. Please log in and try again

代码抛出错误

        $helper = $fb->getRedirectLoginHelper();
        $loginUrl = $helper->getLoginUrl("https://apps.facebook.com/{$appname}/", $permissions);
        echo "<script>window.top.location.href='".$loginUrl."'</script>";

错误

您尚未登录:您尚未登录。请登录并重试。

抛出错误的url是(用appname替换了我的appname):

https://www.facebook.com/v2.7/dialog/oauth?client_id=8651003434372244&state=f2ad3183f9f04355435434534776ae19688ac&response_type=code&sdk=php-sdk-5.3.1&redirect_uri=https%3A%2F%2Fapps.facebook.com%2Fappname%2F&scope=电子邮件

完整的脚本

     <?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>";
    }

抛出此错误是因为我没有添加我的应用程序的画布URL(例如https://apps.facebook.com/appname/

Facebook登录 - >有效OAuth重定向URI下的设置

您必须在API的以下部分设置所需URL的权限:

  • 产品 - > Facebook登录 - >配置 - > OAuth URi
  • 在配置>基本上,设置您的站点URL
  • 在Configurations> Advanced上,设置允许的URI列表以进行共享重定向。

如果您打算在暂存环境中测试应用程序,请将iPhone Store ID字段留空,这样您就可以保存当前平台并进行测试。

当我尝试使用localhost测试登录facebook时,我有相同的警报。 然后我将http:// localhost:3000添加到Valid OAuth重定向URI并再次尝试测试。 这对我有用。 谢谢@Harkirat Saluja

Facebook的简单FIX :您尚未登录:您尚未登录。请登录并重试

关闭客户端OAuth登录启用标准OAuth客户端令牌流。 通过以下选项锁定允许哪些令牌重定向URI,保护您的应用程序并防止滥用。 如果不使用则禁用全局

这是您的应用设置下的TOP按钮。

希望这可以帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM