簡體   English   中英

解決致命錯誤:在 facebook 身份驗證期間調用未定義的方法 Facebook::getSession()

[英]resolving Fatal error: Call to undefined method Facebook::getSession() during facebook authentication

我目前正在為我的 web 頁面處理 facebook 連接登錄頁面。

但我一直在第 24 行收到“調用未定義方法”錯誤消息:

$session = $facebook->getSession();

當我刪除第 24 行時,一切似乎都運行順利。

正如我在http://www.9lessons.info/2011/01/facebook-graph-api-connect-with-php-and.htmlZ80791B3AE7002FAAtutorials24/68tsDplus.com /88C24/68tsDplus 上的教程一樣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();
    ?>

這是一個老問題,但記錄在案:

對於快速解決方案,將所有對getSession()的引用替換為getUser()

例子:

$session = $facebook->getSession();

它應該說:

$session = $facebook->getUser();

參考:升級到 PHP SDK v3.0.0

此外,如果您不想編輯代碼,您可能希望恢復為 2.x sdk。

https://github.com/facebook/php-sdk/zipball/v2.1.2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM