【问题标题】:Uncaught GraphMethodException: Unsupported get request未捕获的 GraphMethodException:不支持的获取请求
【发布时间】:2014-09-17 21:52:43
【问题描述】:

当我尝试从我的网站使用 facebook 登录时,出现此错误

致命错误:未捕获的 GraphMethodException:不支持的获取请求。请阅读位于/home2/******/public_html/includes/facebook/base_facebook.php 第 1271 行的https://developers.facebook.com/docs/graph-api 的 Graph API 文档

一开始,一切都很好。我没有改变任何东西。我该怎么做才能解决这个问题?

/**
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;
}

【问题讨论】:

  • 当你得到那个错误时你在做什么请求
  • 发布流和电子邮件
  • 我很确定这不是您正在做的请求。但是显示代码以及致命事件发生在哪一行
  • 看看那个链接“facebook.com/dialog/…”和第1271行$e = new FacebookApiException($result);
  • 这不是您发送的请求

标签: php facebook facebook-graph-api


【解决方案1】:

需要'../src/facebook.php';

// 创建我们的应用程序实例(将其替换为您的 appId 和密码)。

$facebook = 新的 Facebook(数组(

'appId' => '344617158898614', '秘密' => '6dc8ac871858b34798bc2488200e503d',

));

// 获取用户ID

$user = $facebook->getUser();

// 根据用户是否登录,我们可能拥有也可能不拥有这些数据。

// 如果我们这里有一个$user id,这意味着我们知道用户已经登录了

// Facebook,但我们不知道访问令牌是否有效。访问

// 如果用户退出 Facebook,则令牌无效。

如果($用户){

试试{

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

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

}

catch (FacebookApiException $e) { 错误日志($e);

$user = null;

}

}

// 根据当前用户状态需要登录或注销 url。

如果($用户) {

$logoutUrl = $facebook->getLogoutUrl();

} 别的 {

$loginUrl = $facebook->getLoginUrl();

}

// 由于我们正在获取公共数据,因此此调用将始终有效。

$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']; ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-13
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    • 2016-03-17
    • 2012-11-24
    相关资源
    最近更新 更多