0
votes

When I try to login with facebook from my website, this error occurs

Fatal error: Uncaught GraphMethodException: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api thrown in /home2/******/public_html/includes/facebook/base_facebook.php on line 1271

At the beginning, everything was alright. I haven't changed anything. What should I do to solve this?

/**
Analyzes the supplied result to see if it was thrown
because the access token is no longer valid.  If that is
the case, then we destroy the session.

@param $result array A record storing the error message returned
                    by a failed API call.
**/
protected function throwAPIException($result) {
$e = new FacebookApiException($result);
switch ($e->getType()) {
// OAuth 2.0 Draft 00 style
  case 'OAuthException':
  // OAuth 2.0 Draft 10 style
  case 'invalid_token':
    // REST server errors are just Exceptions
  case 'Exception':
    $message = $e->getMessage();
    if ((strpos($message, 'Error validating access token') !== false) ||
        (strpos($message, 'Invalid OAuth access token') !== false) ||
        (strpos($message, 'An active access token must be used') !== false)
    ) {
      $this->destroySession();
    }
    break;
}

throw $e;
}
1
What request are you doing when you get that error - WizKid
publish_stream and email - Okay Babur
I'm pretty sure that is not the request you are doing. But show the code and which line that the fatal happen on - WizKid
Look at that link " facebook.com/dialog/… " and line 1271 $e = new FacebookApiException($result); - Okay Babur
That is not the request your are sending - WizKid

1 Answers

0
votes

require '../src/facebook.php';

// Create our Application instance (replace this with your appId and secret).

$facebook = new Facebook(array(

'appId' => '344617158898614', 'secret' => '6dc8ac871858b34798bc2488200e503d',

));

// Get User ID

$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.

// If we have a $user id here, it means we know the user is logged into

// Facebook, but we don't know if the access token is valid. An access

// token is invalid if the user logged out of Facebook.

if ($user) {

try {

// Proceed knowing you have a logged in user who's authenticated.

$user_profile = $facebook->api('/me');

}

catch (FacebookApiException $e) { error_log($e);

$user = null;

}

}

// Login or logout url will be needed depending on current user state.

if ($user) {

$logoutUrl = $facebook->getLogoutUrl();

} else {

$loginUrl = $facebook->getLoginUrl();

}

// This call will always work since we are fetching public data.

$naitik = $facebook->api('/naitik');

?>

<title>php-sdk</title>

<style>

  body 

{

    font-family: 'Lucida Grande', Verdana, Arial, sans-serif;

  }

  h1 a

{

    text-decoration: none;

    color: #3b5998;

  }

  h1 a:hover

{

    text-decoration: underline;

  }

</style>

<h1>php-sdk</h1>


<?php if ($user): ?>

  <a href="<?php echo $logoutUrl; ?>">Logout</a>

<?php else: ?>

  <div>

    Login using OAuth 2.0 handled by the PHP SDK:

    <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>

  </div>

<?php endif ?>



<h3>PHP Session</h3>

<pre><?php print_r($_SESSION); ?></pre>


<?php if ($user): ?>

  <h3>You</h3>

  <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">


  <h3>Your User Object (/me)</h3>

  <pre><?php print_r($user_profile); ?></pre>

<?php else: ?>

  <strong><em>You are not Connected.</em></strong>

<?php endif ?>

<h3>Public profile of Naitik</h3>

<img src="https://graph.facebook.com/naitik/picture">

<?php echo $naitik['name']; ?>