对于谷歌的OAuth,我遇到了一些小问题,我使用了CodeIgniter的(http://codeigniter.com/wiki/OAuth_for_Google),但是当我使用CodeIgniter的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)消息:无法修改标题信息-已发送的标题(输出从
文件名:库/行号: 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']='';
}
就在我的功能之前但它什么也做不了..。我要把我的会话变量交给谷歌.不是吗?我能从谷歌那里得到我的代金券吗?
发布于 2011-12-08 09:53:37
老实说,我不确定PHP代码将如何管理会话,因此对您没有什么帮助。似乎这条线是导致
$oauth = $this->google_oauth->get_access_token(false, $token_secret);
您正试图从谷歌获得access_token,以便向Google发送请求,以获取用户信息,这些用户信息曾经授权过您的应用程序,我猜Google并没有返回他们所期望的内容。这可能是由于请求数据中的类型不匹配,如Google对您的期望以及您实际发送的内容。
在您的例子中,我会使用Eclipse的调试器来查看到底发生了什么,但是对于OAuth,我已经在前面的问题中告诉过您了
获取数据。
https://stackoverflow.com/questions/8428547
复制相似问题