php - 解决 fatal error :在 Facebook 身份验证期间调用未定义的方法 Facebook::getSession()

标签 php facebook

我目前正在为我的网页开发 Facebook 连接登录页面。

但我一直在第 24 行收到“调用未定义方法”错误消息:

$session = $facebook->getSession();

当我删除第 24 行时,一切似乎都运行顺利。

因为我正在学习 http://www.9lessons.info/2011/01/facebook-graph-api-connect-with-php-and.html 上的教程和 http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/ - 这有点让我难过!

错误信息是

Fatal error: Call to undefined method Facebook::getSession() in C:\xampp\htdocs\kite\index.php on line 24 

请帮忙。提前谢谢了。这是我的代码:

<?php session_start();

    //config
    include "resources/Connections/kite.php";

    //connect to the database so we can check, edit, or insert data to our users table
    $con = mysql_connect($hostname_kite, $username_kite, $password_kite) or die(mysql_error());
    $db = mysql_select_db($database_kite, $con) or die(mysql_error());

    //include out functions file giving us access to the protect() function made earlier
    include "resources/php/functions.php";

    //setup facebook connect
    require 'resources/facebook/src/facebook.php';
    $facebook = new Facebook(array(
      'appId'  => $appid_kite,
      'secret' => $secret_kite,
    ));

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

    // Let's see if we have an active session
    $session = $facebook->getSession();

    // 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();
    }
    ob_start();
    ?>

最佳答案

这是一个老问题,但为了记录:

For a fast solution replace all references to getSession() with getUser()

例子:

$session = $facebook->getSession();

它应该说:

$session = $facebook->getUser();

引用:Upgrade to PHP SDK v3.0.0

关于php - 解决 fatal error :在 Facebook 身份验证期间调用未定义的方法 Facebook::getSession(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6119856/

相关文章:

php - Facebook用户信息存储在数据库中

facebook - 如何确定 Facebook 事件的 "category"?

node.js - 无法在 Facebook Graph API 上使用/apprequests 端点

一天的 PhP 时间戳

javascript - Fineuploader 未设置 x-amz-credentials

php - 使用两个时间戳列之间的差异在 MySQL 中过滤表

php - 如何以人类可读的格式输出(到日志)多级数组?

javascript - 推迟广告脚本执行

facebook - Facebook 上的 NetworkOnMainThreadException 使用 Phonegap 1.6.0 登录

ios - iOS 上不显示应用属性