所以我最終實現了「Facebook_Volatile」級這樣的:
/**
* Extends the BaseFacebook class with the intent of NOT using
* PHP sessions to store user ids and access tokens.
* @Author Felipe Guaycuru <[email protected]>
*/
class FacebookVolatile extends BaseFacebook
{
// Stores the shared session ID if one is set.
//protected $sharedSessionID;
// Stores data non-persistently
private $storage = array();
/**
* Identical to the parent constructor.
*
* @param Array $config the application configuration.
* @param String $access_token the supplied access token.
* @see BaseFacebook::__construct in facebook.php
*/
public function __construct($config, $access_token) {
parent::__construct($config);
$this->setAccessToken($access_token);
}
protected static $kSupportedKeys =
array('state', 'code', 'access_token', 'user_id');
/**
* Provides the implementations of the inherited abstract
* methods. The implementation uses class properties to maintain
* a store for authorization codes, user ids, CSRF states, and
* access tokens.
*/
protected function setPersistentData($key, $value) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to setPersistentData.');
return;
}
$this->storage[$key] = $value;
}
protected function getPersistentData($key, $default = false) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to getPersistentData.');
return $default;
}
return isset($this->storage[$key]) ?
$this->storage[$key] : $default;
}
protected function clearPersistentData($key) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to clearPersistentData.');
return;
}
unset($this->storage[$key]);
}
protected function clearAllPersistentData() {
foreach (self::$kSupportedKeys as $key) {
$this->clearPersistentData($key);
}
}
}
因此,在我的PHP後臺,我收到了$access_token
,並使用它像這樣:
$FB = new FacebookVolatile(array(
'appId' => CONFIG_FACEBOOK_APP_ID,
'secret' => CONFIG_FACEBOOK_APP_SECRET,
), $access_token);
那麼我可以用通常情況下,如果與JS SDK一起使用它一模一樣