2
我試圖使用philsturgeon's OATH2 spark for CodeIgniter來驗證使用Facebook的用戶。我安裝了Spark並嘗試了他在github中給出的用法示例。在非對象上調用成員函數set_userdata()Codeigniter OAuth2
在下面的代碼中,我只改變了id和密碼。
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Auth extends CI_Controller
{
public function session($provider)
{
$this->load->helper('url_helper');
$this->load->spark('oauth2-0.4.0');
$provider = $this->oauth2->provider($provider, array(
'id' => 'My_ID',
'secret' => 'MY_Secret',
));
if (! $this->input->get('code'))
{
// By sending no options it'll come back here
$provider->authorize();
}
else
{
// Howzit?
try
{
$token = $provider->access($_GET['code']);
$user = $provider->get_user_info($token);
// Here you should use this information to A) look for a user B) help a new user sign up with existing data.
// If you store it all in a cookie and redirect to a registration page this is crazy-simple.
echo "<pre>Tokens: ";
var_dump($token);
echo "\n\nUser Info: ";
var_dump($user);
}
catch (OAuth2_Exception $e)
{
show_error('That didnt work: '.$e);
}
}
}
}
但是,當我試圖調用使用
http://localhost/tddd27/index.php/auth/session/facebook
我得到以下控制器:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Auth::$session
Filename: libraries/Provider.php
Line Number: 117
Fatal error: Call to a member function set_userdata() on a non-object in
C:\ XAMPP \ htdocs中\ tddd27 \火花\ oauth2-0.4 .0 \ libraries \ Provider.php在線117
圖書館有問題或者我做錯了什麼?
你是真正的加入這個靠近你的功能
你也可以有庫自動加載的頂部。這是問題所在 – 2013-05-01 05:59:06