首页 文章

Facebook php示例:致命错误

提问于
浏览
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}

1 回答

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

    显然它没有!

相关问题