0
private $_api_key;
private $_api_secret;
private $_token_url = 'oauth/access_token';
private $_user_url = 'me';
private $_data = array();
function __construct()
{
$this->_obj =$CI =& get_instance();
$fb_api_id = $CI->db->get_where('settings', array('code' => 'SITE_FB_API_ID'))->row()->string_value;
$fb_api_secret = $CI->db->get_where('settings', array('code' => 'SITE_FB_API_SECRET'))->row()->string_value;
$this->_api_key = $fb_api_id;
$this->_api_secret = $fb_api_secret;
$this->_token_url = $this->_obj->config->item('facebook_api_url').$this->_token_url;
$this->_user_url = $this->_obj->config->item('facebook_api_url').$this->_user_url;
$this->_set('scope', $this->_obj->config->item('facebook_default_scope'));
$this->connection = new facebookConnection();
if (!$this->logged_in())
{
// Initializes the callback to this page URL.
$this->set_callback();
}
}
public function logged_in()
{
return ($this->get() === NULL) ? FALSE : TRUE;
}
public function logout()
{
$this->_unset('token');
$this->_unset('user');
}
public function login_url($scope = NULL)
{
$url = "http://www.facebook.com/dialog/oauth?client_id=".$this->_api_key.'&redirect_uri='.urlencode($this->_get('callback'));
if (empty($scope))
{
$scope = $this->_get('scope');
}
else
{
$this->_set('scope', $scope);
}
if (!empty($scope))
{
$url .= '&scope='.$scope;
}
return $url;
}
public function login($scope = NULL)
{
$this->logout();
if (!$this->_get('callback')) $this->_set('callback', current_url());
$url = $this->login_url($scope);
return redirect($url);
}
public function get()
{
$token = $this->_find_token();
if (empty($token)) return NULL;
// $user = $this->_get('user');
// if (!empty($user)) return $user;
try
{
$user = $this->connection->get($this->_user_url.'?'.$this->_token_string());
}
catch (facebookException $e)
{
$this->logout();
return NULL;
}
// $this->_set('user', $user);
return $user;
}
private function _find_token()
{
$token = $this->_get('token');
if (!empty($token))
{
if (!empty($token->expires) && intval($token->expires) >= time())
{
// Problem, token is expired!
return $this->logout();
}
$this->_set('token', $token);
return $this->_token_string();
}
if (!isset($_GET['code']))
{
return $this->logout();
}
if (!$this->_get('callback')) $this->_set('callback', current_url());
$token_url = $this->_token_url.'?client_id='.$this->_api_key."&client_secret=".$this->_api_secret."&code=".$_GET['code'].'&redirect_uri='.urlencode($this->_get('callback'));
try
{
$token = $this->connection->get($token_url);
}
catch (facebookException $e)
{
$this->logout();
redirect($this->_strip_query());
return NULL;
}
$this->_unset('callback');
if ($token->access_token)
{
if (!empty($token->expires))
{
$token->expires = strval(time() + intval($token->expires));
}
$this->_set('token', $token);
redirect($this->_strip_query());
}
return $this->_token_string();
}
private function _get($key)
{
$key = '_facebook_'.$key;
return $this->_obj->session->userdata($key);
}
private function _set($key, $data)
{
$key = '_facebook_'.$key;
$this->_obj->session->set_userdata($key, $data);
}
private function _unset($key)
{
$key = '_facebook_'.$key;
$this->_obj->session->unset_userdata($key);
}
public function set_callback($url = NULL)
{
$this->_set('callback', $this->_strip_query($url));
}
private function _token_string()
{
return 'access_token='.$this->_get('token')->access_token;
}
public function append_token($url)
{
if ($this->_get('token')) $url .= '?'.$this->_token_string();
return $url;
}
private function _strip_query($url = NULL)
{
if ($url === NULL)
{
$url = (empty($_SERVER['HTTPS'])) ? 'http' : 'https';
$url .= '://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
$parts = explode('?', $url);
return $parts[0];
}
サイト内のfbアカウントを使用してサインインしようとすると、トークンとして何かすべてがfacebookから取得されます。 Facebookからのトークンはサインアップのために取得されませんか? access_token(非オブジェクトのプロパティを取得しようとしている)
私はこのコードでfollowinエラーを取得:メッセージ:ライブラリ/ Facebook_Lib.php
行番号:454
非オブジェクトのプロパティ
ファイル名を取得しようPHPエラーが発生しました
重大度:通知
メッセージ:非オブジェクトのプロパティを取得しようとすると
ファイル名:ライブラリ/ Facebook_Lib.phpは
行番号:493
重要度は:
メッセージに注意してください:非のプロパティを取得しようとすると、
ファイル名を-OBJECT:ライブラリ/ Facebook_Lib.ph
行番号:493
access_tokenに関するすべてのエラー
行番号付きのスタックトレースとは、私たちには役に立ちません(行番号は表示されません)。ノイズを減らすためにコードをトリムしてください。 – Nix