所以我最终实现了一个像这样的“Facebook_Volatile”类:
/**
* Extends the BaseFacebook class with the intent of NOT using
* PHP sessions to store user ids and access tokens.
* @Author Felipe Guaycuru <guaycuru@gmail.com>
*/
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);
然后就可以$FB
正常使用了,和JS SDK一起使用完全一样