我在使用 OAuth for Google 时遇到了一点问题,我使用 Jim Saunder Libraire for CodeIgniter (http://codeigniter.com/wiki/OAuth_for_Google) 但是当我使用 access_youtube 函数时,它看起来像这样:
public function access_youtube()
{ //STEP 2
// Here is the first call to load the library
$params['key'] = 's390075769.onlinehome.fr';
$params['secret'] = 'iHD72YKzWmbm8VTwncht_E-d';
// We can change the signing algorithm and http method by setting the following in your params array.
$params['algorithm'] = 'HMAC-SHA1';
// $params['method'] = "GET";
// We need to reload the library since we left our site beetween Step 1 & 2.
$this->load->library('google_oauth', $params);
// We are using HMAC signing you need to specify the token_secret you got from the request step as the second parameter of this method. So
$token_secret = $this->session->userdata('token_secret');
$oauth = $this->google_oauth->get_access_token(false, $token_secret);
// The access method will return an array with keys of ‘oauth_token’, and ‘oauth_token_secret’
// These values are your access token and your access token secret. We should store these in our database.
$this->session->set_userdata('oauth_token', $oauth['oauth_token']);
$this->session->set_userdata('oauth_token_secret', $oauth['oauth_token_secret']);
// Now you have an access token and can make google service requests on your users behalf
redirect(site_url());
}
我收到了几条错误消息:
未定义索引:oauth_token
未定义索引:oauth_token_secret
它指的是 $this->session->set_userdata ...
并且,在每条错误消息之后,我得到:
消息:无法修改标头信息 - 标头已发送(输出开始于 /homepages/7/d390075755/htdocs/system/core/Exceptions.php:170) 文件名:libraries/Session.php 行号:671
我认为这与之前的错误消息有关。
所以我在构造函数中尝试了:
class Example extends CI_Controller
{
private $CI;
public function __construct()
{
parent::__construct();
$this->CI =& get_instance();
$this->CI->load->library('session');
$oauth = array();
$oauth['oauth_token_secret']='';
$oauth['oauth_token']='';
}
就在我的函数之前,但它什么也没做......而且我担心我会被谷歌丢失我的会话变量库存......不是吗?我是否从 google 获取我的令牌?