Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Google Oauth for YouTube:我为什么得到;未定义索引:oauth“U标记”;(Jim S.&x27;代码)_Php_Codeigniter_Oauth_Youtube_Google Openid - Fatal编程技术网

Php Google Oauth for YouTube:我为什么得到;未定义索引:oauth“U标记”;(Jim S.&x27;代码)

Php Google Oauth for YouTube:我为什么得到;未定义索引:oauth“U标记”;(Jim S.&x27;代码),php,codeigniter,oauth,youtube,google-openid,Php,Codeigniter,Oauth,Youtube,Google Openid,我对Google的OAuth有点问题,我使用Jim Saunder Librarire作为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'] =

我对Google的OAuth有点问题,我使用Jim Saunder Librarire作为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_令牌

未定义索引:oauth\u令牌\u机密

其中引用了行$this->session->set\u userdata

并且,在每次收到错误消息后:

消息:无法修改标题信息-标题已由发送(输出开始于/homepages/7/d3900755/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']='';

}

就在我的功能之前但它什么都没做。。我很震惊,我要用谷歌卖掉我的会话变量股票。。。不是吗?我是从谷歌那里得到代币的吗?

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

$oauth = $this->google_oauth->get_access_token(false, $token_secret);
您正试图从Google获取access_令牌,以便向Google API发送请求,以获取授权您的应用程序的用户信息,我猜Google不会返回他们期望的结果。 这可能是由于请求数据中的类型不匹配,例如Google Oauth期望您发送的内容和实际发送的内容

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

  • 您需要存储第一步获得的代币
  • 一旦您的用户从自我验证中返回,您需要使用该请求令牌获取访问令牌
  • 一旦您有了请求令牌,您就可以进行最后的API调用了,您的代码似乎无法从会话中获取数据

  • 再次感谢你,umesh,我发现了我的问题:一切都是因为我的url:事实上,当我从google检索我的url时,我得到了所有必要的信息,正如上面写的那样:但事实上这个url没有正确返回,所以当我手动更正它时,我所做的是更改所有的%2F by/和=&by?,上次我忘了在“oauth_token=”之后更改一个,所以访问函数没有获得oauth token,这就是为什么它不能工作的原因,那么我如何编码它以自动获得正确的url呢?我的意思是它必须自动更改所有的%2F和&=值。我该怎么做?很抱歉解析了答案,如果你点击我的链接,你会自己看到它,尝试访问,然后在授权应用程序后更改你得到的url,检查url并手动更改,你会在打印会话数据中看到(在标题中)oauth令牌和oauth令牌机密there@user1083453:在这种情况下,您需要使用url编码,如示例所示,这基本上是url已编码为空格,其他内容已协调一致。您需要将其返回到PHP代码中,就像您可以通过放置没有名字。