Facebook: You are not logged in: You are not logged in. Log in and try again.

the code causes an 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. Log in and try again.

The url that causes 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-52F2%F%%%%%%%%%% 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>";
    }
+4
source share
5 answers

This error was selected due to the fact that I did not add the application canvas URL (example https://apps.facebook.com/appname/ ) to

Facebook Login- > URI OAuth

+8

, iPhone , .

0

URL- API:

  • → Facebook Logins → → OAuth URi's
  • "" > "" URL- .
  • > URI .
0

, facebook localhost. http://localhost:3000 URI OAuth . . @

0

FIX Facebook: : .

OAuth Login OAuth. , , URI- . ,

TOP .

,

-1
source

Source: https://habr.com/ru/post/1658157/


All Articles