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

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

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


You have to setup the permissions to the desired URL's on the following sections of the API:

  • 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.

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.


I have same alert when I try test login facebook with localhost. Then I add http://localhost:3000 to Valid OAuth redirect URIs and try test again. This worked for me. Thank you @Harkirat Saluja


The simple FIX for the Facebook : You are not logged in: You are not logged in. Please log in and try again

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

This the the TOP button under your app settings.

Hope this helps


Need Your Help

How to get assembly output from building with Cargo?

assembly rust rust-cargo

While I've seen docs on using rustc directly to output assembly, having to manually extract commands used by Cargo and edit them to write assembly is tedious.