0

我正在尝试制作一个 php facebook 应用程序。下载 Facebook php sdk 并使用 example.php(使用我自己的 appId 和 secret)来尝试运行示例应用程序。我可以使用示例应用程序,但是当我单击使用 facebook 登录并验证应用程序时,它会引发此异常:

“致命错误:未捕获的 GraphMethodException:不支持的获取请求。在第 1264 行的 /var/www/facebook_test/base_facebook.php 中抛出”

下面是我正在使用的代码。

任何指导将不胜感激。

<?php
require 'facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'myappid',
  'secret' => 'mysecretid',
  'cookie' => true,
));

// Get User ID
$user = $facebook->getUser();

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 {
  $statusUrl = $facebook->getLoginStatusUrl();
  $loginUrl = $facebook->getLoginUrl();
}

// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');

?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <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>
  </head>
  <body>
    <h1>php-sdk</h1>

    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Check the login status using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo urldecode($statusUrl); ?>">Check the login status</a>
      </div>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo urldecode($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']; ?>
  </body>
</html>

编辑:这是堆栈跟踪:

#0 /var/www/facebook_test/base_facebook.php(873): 
BaseFacebook->throwAPIException(Array) #1 [internal function]: 
BaseFacebook->_graph('/naitik') #2 /var/www/facebook_test/base_facebook.php(647): 
call_user_func_array(Array, Array) #3 /var/www/facebook_test/index.php(66): 
BaseFacebook->api('/naitik') #4 {main}
4

1 回答 1

1
// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');

显然不是!

于 2013-10-16T16:20:50.713 回答