2012-03-08 78 views
1

我正在研究一个基本上将在Kiosk中运行的应用程序,重点在于允许用户在他们处于业务状态时能够登录Facebook并记录日志在其中发布一条消息,说他们在那里,给他们后续优惠券。facebook php api多个用户一台计算机强制注销

问题出现了,他们登录后又注销后,下一个用他们的账户登录的用户以前一个用户的身份登录,这种情况持续不断。

获得优惠券后,脚本会在15秒后自动将其注销,并将应用程序返回到下一个用户的主屏幕。当他们登录时,他们能够做到这一点,将它们返回到要求发布权限的页面,但是它拉取了以前的所有用户信息。这是在发送到Facebook上登录后在页面中调用的代码。

<?php 
//include the Facebook PHP SDK 
include_once 'couponGenerator/facebook.php'; 

//start the session if necessary 
if(session_id()) { 

} else { 
session_start(); 
} 

//instantiate the Facebook library with the APP ID and APP SECRET 
$facebook = new Facebook(array(
'appId' => '00000000000', 
'secret' => '000000000000000000000', 
'cookie' => true, 
'status' => true, 
'oath' => true 
)); 

$access_token = $facebook->getAccessToken(); 
$_SESSION['active'][$access_token]; 
//get the news feed of the active page using the page's access token 
$page_feed = $facebook->api(
'/me/feed', 
'GET', 
array(
    'access_token' => $_SESSION['active']['access_token'] 
) 
); 
$fbuser = $facebook->api('/me'); 
//var_dump($page_feed); exit; 
?> 

我已尝试对Facebook的删除cookie和session的主页,这并没有解决什么,我只是想弄清楚我在做什么错了,任何的建议是非常值得欢迎的。

$facebook->destroySession(); 
$facebook->_killFacebookCookies(); 

public function _killFacebookCookies() 
{ 
    // get your api key 
    $apiKey = $this->getAppId(); 
    // get name of the cookie 
    $cookie = $this->getSignedRequestCookieName(); 

    $cookies = array('user', 'session_key', 'expires', 'ss'); 
    foreach ($cookies as $name) 
    { 
     setcookie($apiKey . '_' . $name, false, time() - 3600); 
     unset($_COOKIE[$apiKey . '_' . $name]); 
    } 

    setcookie($apiKey, false, time() - 3600); 
    unset($_COOKIE[$apiKey]); 
    $this->clearAllPersistentData(); 
    } 

以下是更新后的连接类 `

<?php 
//include the Facebook PHP SDK 
include_once 'facebook.php'; 

//instantiate the Facebook library with the APP ID and APP SECRET 
$facebook = new Facebook(array(
    'appId' => '122628977190080', 
    'secret' => '123123123123123123123123', 
    'cookie' => true 
)); 
    $access_token = $facebook->getAccessToken(); 
    unset ($_SESSION['active'][$access_token]); 
    session_unregister ($_SESSION['active'][$access_token]); 
//Get the FB UID of the currently logged in user 
$user = $facebook->getUser(); 

//if the user has already allowed the application, you'll be able to get his/her FB UID 
if($user) { 
    //start the session if needed 
    if(session_id()) { 

    } else { 
     session_start(); 
    } 

    //do stuff when already logged in 

    //get the user's access token 
    $access_token = $facebook->getAccessToken(); 

    //check permissions list 
    $permissions_list = $facebook->api(
     '/me/permissions', 
     'GET', 
     array(
      'access_token' => $access_token 
     ) 
    ); 

    //check if the permissions we need have been allowed by the user 
    //if not then redirect them again to facebook's permissions page 
    $permissions_needed = array('publish_stream', 'email'); 
    foreach($permissions_needed as $perm) { 
     if(!isset($permissions_list['data'][0][$perm]) || $permissions_list['data'][0][$perm] != 1) { 
      $login_url_params = array(
       'scope' => 'publish_stream,email', 
       'fbconnect' => 1, 
       'display' => "page", 
       'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] 
      ); 
      $login_url = $facebook->getLoginUrl($login_url_params); 
      header("Location: {$login_url}"); 
      exit(); 
     } 
    } 

    //if the user has allowed all the permissions we need, 
    //get the information about the pages that he or she managers 
    $accounts = $facebook->api(
     '/me/accounts', 
     'GET', 
     array(
      'access_token' => $access_token 
     ) 
    ); 

    //save the information inside the session 
    $_SESSION['access_token'] = $access_token; 
    $_SESSION['accounts'] = $accounts['data']; 
    //save the first page as the default active page 
    $_SESSION['active'] = $accounts['data'][0]; 

    //redirect to manage.php 
    header('Location: ../facebook_result.php'); 
} else { 
    //if not, let's redirect to the ALLOW page so we can get access 
    //Create a login URL using the Facebook library's getLoginUrl() method 
    $login_url_params = array(
     'scope' => 'read_stream,email', 
     'fbconnect' => 1, 
     'display' => "page", 
     'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] 
    ); 
    $login_url = $facebook->getLoginUrl($login_url_params); 

    //redirect to the login URL on facebook 
    header("Location: {$login_url}"); 
    exit(); 
} 

?>`

调用注销脚本后,我在网页上运行这段代码,看看是否一切组。

<?php 
     try { 
    $uid = $facebook->getUser(); 
    $fbme = $facebook->api('/me'); 
    echo "$uid"; 
} catch (FacebookApiException $e) { 
    print_r($e); 
} 
     ?> 

它给了我这样的结果

FacebookApiException Object ([result:protected] => 
Array ([error] => Array ([message] => 
An active access token must be used to query information about the current user. 
[type] => OAuthException [code] => 2500)) 
[message:protected] => An active access token must be 
used to query information about the current user. 
[string:private] => [code:protected] => 0 [file:protected] => 
/home/m3dev/public_html/couponsite/couponGenerator/base_facebook.php 

[line:protected] => 1046 [trace:private] => Array ([0] => Array ([file] => /home/m3dev/public_html/couponsite/couponGenerator/base_facebook.php [line] => 751 [function] => throwAPIException [class] => BaseFacebook [type] => -> [args] => Array ([0] => Array ([error] => Array ([message] => An active access token must be used to query information about the current user. [type] => OAuthException [code] => 2500)))) [1] => Array ([function] => _graph [class] => BaseFacebook [type] => -> [args] => Array ([0] => /me)) [2] => Array ([file] => /home/m3dev/public_html/couponsite/couponGenerator/base_facebook.php [line] => 560 [function] => call_user_func_array [args] => Array ([0] => Array ([0] => Facebook Object ([appId:protected] => 162628977190080 [apiSecret:protected] => **SECRET KEY REMOVED ** [user:protected] => 0 [signedRequest:protected] => Array ([algorithm] => HMAC-SHA256 [code] => 961628b1ca0354544541d58e.1-34319949|p3D3pSNoawlC1wBllhiN7zoEpJY [issued_at] => 1331218933 [user_id] => 34319949) [state:protected] => [accessToken:protected] => 162628977190080|**SECRET KEY REMOVED** [fileUploadSupport:protected] =>) [1] => _graph) [1] => Array ([0] => /me))) [3] => Array ([file] => /home/m3dev/public_html/couponsite/index.php [line] => 71 [function] => api [class] => BaseFacebook [type] => -> [args] => Array ([0] => /me)))) 

回答

1

你可能会摧毁一个Facebook会话,但你似乎并不被摧毁你自己的会话。

清除出

$_SESSION['active'][$access_token]; 
+0

无效,当用户b登录后用户a登录时,它会提取用户a的信息。 – jeremiah 2012-03-08 05:37:07

+0

你是否能够看到它是否将相同的访问令牌拉出会话? – 2012-03-08 05:54:06

+0

我返回访问令牌,它返回为空 如果您的意思不是这样,它似乎每次它回来时都会为前一个登录的人员,当新人登录时拉取令牌。 – jeremiah 2012-03-08 05:56:18

0

您需要强制Facebook Re-Authentication为每个用户。

我不知道,如果你正在使用支持PHP的API这一点,但OAuth的对话框可以接收auth_type当重视对reauthenticate强制用户提供他的凭据:

$dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
      . $app_id . "&redirect_uri=" . urlencode($my_url) 
      . '&auth_type=reauthenticate&auth_nonce=' . $auth_nonce; 

这可以也可以使用JavaScript API。