12

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>";
    }
scriptkiddie
  • 585
  • 2
  • 8
  • 24
  • Most likely a session/cookie problem. // Do yourself, and more importantly, the users of your app a favor, and use the JS SDK for login in a canvas app - it makes for a much smoother experience. – CBroe Oct 19 '16 at 10:36
  • Thank you bro for your suggestion – scriptkiddie Oct 19 '16 at 11:07
  • I am experiencing this issue also on Web application, redirect_uri matches exactly to the config in Client OAuth Settings - see more on https://developers.facebook.com/support/bugs/232085950706415/ need help anyone.. thanks in advance – josevoid May 28 '18 at 07:25

5 Answers5

20

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

scriptkiddie
  • 585
  • 2
  • 8
  • 24
  • Remember that these URLs are "scheme-sensitive". That means that if you are using an SSL URL in your FB config (e.g. `https://example.com`), then the non-SSL version (e.g. `http://example.com`) will not work; it will generate the "You are not logged in" error. – rinogo Aug 13 '18 at 21:13
  • Thank you! i've been hitting my head against the wall for 1h trying to figure out what's wrong. – lordZ3d Mar 14 '19 at 09:38
2

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.
Fernando Wolff
  • 216
  • 3
  • 6
0

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.

Marcos Curvello
  • 873
  • 13
  • 25
0

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

Kakashi
  • 534
  • 11
  • 16
-1

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