Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

facebook

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) :

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=email

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>";
    }
like image 669
scriptkiddie Avatar asked Oct 19 '16 05:10

scriptkiddie


People also ask

How do you fix logging into this app with Facebook is not available at this time?

How to Fix Login Error in Facebook via App. To fix this error, simply install the Facebook app from Google Play Store or App Store. Once installed, login your account and approved some required permission to your device and you're set to go.

Why does Facebook not let me log in and log in?

If you can't log into Facebook account, it might because of the following reasons: forgot the Facebook log in details, account hack, Facebook bugs, cache or cookie problems, browser issue, malware/virus infection, the account is disabled by Facebook, etc.

Why does it say login error when I try to login Facebook?

Causes of Facebook Login Error Problem Issue While if you are getting the error while logging in the Facebook app itself then it might be the issue of the network, app cache issues, device issues, etc.

How long is a temporary block from logging in on Facebook?

After you complete a security check, you'll have to wait 24 hours to log into your Facebook account. During this time, your account will still be visible to your friends on Facebook, but you won't be able to access it.


1 Answers

This error was thrown because I have not added my app's canvas url(example https://apps.facebook.com/appname/) in

Facebook Login->settings under Valid OAuth redirect URIs

like image 100
scriptkiddie Avatar answered Sep 22 '22 05:09

scriptkiddie