首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >:为什么我会得到“未定义索引: oauth_token”( Jim .(编码)

:为什么我会得到“未定义索引: oauth_token”( Jim .(编码)
EN

Stack Overflow用户
提问于 2011-12-08 09:06:56
回答 1查看 1.2K关注 0票数 0

对于谷歌的OAuth,我遇到了一些小问题,我使用了CodeIgniter的(http://codeigniter.com/wiki/OAuth_for_Google),但是当我使用CodeIgniter的access_youtube函数时,它看起来是这样的:

代码语言:javascript
运行
复制
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处开始)

我认为这与之前的错误消息有关。

因此,我在构造函数中尝试了这一点:

代码语言:javascript
运行
复制
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']='';

}

就在我的功能之前但它什么也做不了..。我要把我的会话变量交给谷歌.不是吗?我能从谷歌那里得到我的代金券吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-08 09:53:37

老实说,我不确定PHP代码将如何管理会话,因此对您没有什么帮助。似乎这条线是导致

代码语言:javascript
运行
复制
$oauth = $this->google_oauth->get_access_token(false, $token_secret);

您正试图从谷歌获得access_token,以便向Google发送请求,以获取用户信息,这些用户信息曾经授权过您的应用程序,我猜Google并没有返回他们所期望的内容。这可能是由于请求数据中的类型不匹配,如Google对您的期望以及您实际发送的内容。

在您的例子中,我会使用Eclipse的调试器来查看到底发生了什么,但是对于OAuth,我已经在前面的问题中告诉过您了

  1. ,您需要在第一步存储您获得的令牌。当用户身份验证回来时,
  2. -self,您需要使用请求令牌
  3. 来获取access_token,一旦您准备好进行最终的API调用,并且您的代码似乎无法从会话

获取数据。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8428547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档