簡體   English   中英

$ facebook-> getSession(); 不工作。 不知道為什么嗎?

[英]$facebook->getSession(); not working. No idea why?

 <?php

require 'facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => '130407366991766',
  'secret' => '****',
  'cookie' => true,
));

// We may or may not have this data based on a $_GET or $_COOKIE based session.
//
// If we get a session here, it means we found a correctly signed session using
// the Application Secret only Facebook and the Application know. We dont know
// if it is still valid until we make an API call using the session. A session
// can become invalid if it has already expired (should not be getting the
// session back in this case) or if the user logged out of Facebook.
$session = $facebook->getSession();

$me = null;
// Session based API call.
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}

// login or logout url will be needed depending on current user state.
if ($me) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

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

?>

<h1><a href="example.php">php-sdk</a></h1>

<?php if ($me): ?>
<a href="<?php echo $logoutUrl; ?>">
  <img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">
</a>
<?php else: ?>
<a href="<?=$loginUrl?>">
  <img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">
</a>
<?php endif ?>

<h3>Session</h3>
<?php if ($me): ?>
<pre><?php print_r($session); ?></pre>

<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $uid; ?>/picture">
<?php echo $me['name']; ?>

<h3>Your User Object</h3>
<pre><?php print_r($me); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>

<h3>Naitik</h3>
<img src="https://graph.facebook.com/naitik/picture">
<?php echo $naitik['name']; ?>

由於某種原因...盡管登錄似乎工作正常,但我的腳本不斷聲明“您未連接”。

我只能認為這是我的應用程序設置存在問題。 有人有想法么?

演示: http//gua.com/fb-api/

我有完全一樣的問題。 我的整個應用程序壞了,因為getSession()不再起作用。

我下載了最新版本的PHP SDK,並使用該示例初始化了用戶會話。

基本上,會話是在創建Facebook對象后立即初始化的。 因此,從示例代碼開始,當您調用時。

$facebook = new Facebook(array(
  'appId'  => '191149314281714',
  'secret' => '73b67bf1c825fa47efae70a46c18906b',
));

您已經有一個會話。 要獲取用戶ID,您只需致電:

$uid = $facebook->getUser();

如果該調用的結果為0 ,則該用戶未登錄。

Facebook更改為OAuth2和GetSession無法正常工作從開發人員PHP Sdk下載新的base_facebook.php和facebook.php,並將登錄過程替換為:

if( $userfb = $facebook->getUser() ){ 
   try{
        $UserProfile = $facebook->api('/me');
   }catch (FacebookApiException $e) {
      $userfb      = null;
      $UserProfile = null;
}

是在我的網站上工作的新版本無法顯示帶有perms參數的fb:login-button :(而且我無法修復

Facebook已更改了您調用API的方式,並且舊的REST API調用已被棄用。 這意味着getSession()方法不再起作用。

您需要將Api密鑰提供給構造函數。 不是應用程式編號。

暫無
暫無

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

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