YouTube的API请求:我怎么能得到正确的令牌(吉姆S.“code) [英] YouTube API Request : How could I get the Right token ( about Jim S.' code )

查看:130
本文介绍了YouTube的API请求:我怎么能得到正确的令牌(吉姆S.“code)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现我的codeIgniter网站YouTube的API。
我跟着吉姆·桑德斯说明这里:

I’m trying to implement the YouTube API on my codeIgniter website. I followed the Jim Saunders instructions here :

在这里: HTTP://$c$cigniter.com/wiki/OAuth_for_Google/
(大致相同)

and here : http://codeigniter.com/wiki/OAuth_for_Google/ (approximately the same)

所以首先,我需要得到一个 request_youtube 函数令牌的秘密,该功能可以正常工作,我已经进入了谷歌从我的消费者密钥和消费者秘密,一切都刚刚好。于是,我重定向到YouTube的授权YouTube的访问,但是当我重定向到我的网站,我有2个问题:

SO first of all, I needed to get the token secret with a request_youtube function, that function works correctly, i’ve entered my consumer key and consumer secret from google and everything is just fine. So then I’m redirected to YouTube to authorize the YouTube access, but when I’m redirected to my site, I got 2 problems :

我得到的链接:

<$c$c>mywebsite/example/access_youtube=&oauth_verifier=6wbPcxlOAmYQwaDU7HIhz38B&oauth_token=1/6Nfchy_nM-j4vxQzhAWTuc1J20L02bBNdcZasQP-e0s

codeIgniter 不understant的/和不重定向我到例如/ access_youtube 功能,如果我手动纠正它,然后我去我的 access_youtube 函数与我的参数,但这里是第二(致命)的问题我有:

and codeIgniter doesn’t understant the "/" and doesn’t redirect me to the example/access_youtube function, If I correct it manually, then I go to my access_youtube function with my parameters but here is second (fatal) problem I got :

首先,这里有我的两个变量,我从网址获得:

First, here are my two variables I got from the url :

oauth_verifier=6wbPcxlOA************
&
oauth_token=1/6Nfchy_nM-j4vxQzhAWTuc1J20L02b***********

然而,在谷歌OAuth园地(你就可以在这里找到: HTTP://google$c$csamples.com/oauth_playground/)
我应该得到类似的东西:

yet, on the google Oauth Playground (that you’ll be able to find here : http://googlecodesamples.com/oauth_playground/) I’m supposed to get something like that :

oauth_token=1/P9o-yO1Czz1q67pvPm**********************iMI&
oauth_token_secret=CzeSat342hO5HzswJEq94ZPH&oauth_callback_confirmed=true

这样是不是意味着我没有得到相同的变量...为什么?我怎么能拿放入系统变量代替一个我得到了什么?他们是一样的吗?

so that mean I didn’t get the same variables ... why ? how could I get thoses variables instead of the one I got ? Are they the same ?

其次,
我在access_Youtube功能得到了几个错误,CI告诉:

Second, I got several errors in my access_Youtube function, CI tell :


  • -Message:未定义指数:组oauth_token

  • -Message:未定义指数:oauth_token_secret

所以它不会从报头信息......我真的不知道该怎么做,我跟着吉姆的指示,但我是那种卡住了,但有没有人谁试图实现他的网站上OAuth访问有一个想法?

so it doesn’t get informations from the header ... I don’t really know how to do so, I’ve followed the Jim’ Instructions but I’m a kind of stuck there, does anyone who tried to implement an OAuth access on his site has an idea ?

感谢您:)

推荐答案

好吧你在做什么,直到你得到重定向回从谷歌是完全正确的。

Ok what you are doing till you get redirect back from google is perfectly correct.


  1. oauth_verifier

  2. 组oauth_token

oauth_verifier code是一个Google送你回来,如果用户授权您的应用程序,以便令牌你需要这个验证访问得到的accessToken才能访问他/她的个人资料将能够获得访问用户配置/日期您已经定义什么都范围。

oauth_verifier code is one google send you back if user authorize your application to access his/her profile so you need this verifier to get AccessToken with access token you will able to get access to user profile/date what ever scope you have defined.

oauth_token 

这是与应用程序相关联,并确定谷歌你这个它会保持相同的为您aplication

this is associated with your application and Google identify you with this it will remain same for your aplication

所以,当你的GET 的accessToken 从谷歌/你管API调用类似

so when you are get AccessToken from google/you tube API by calling something like

Token token=authGetRequestToken.getRequestToken(service);

此请求令牌包含你的秘密,所以重定向用户之前到YouTube,你需要这个令牌坚持要么数据库或session.Once用户重定向回你的应用需要,一旦你有这个令牌使用取回此令牌与此令牌沿着verification_ code得到ACCESS_TOKEN像

this request token contains your secret, so before redirecting user to youtube you need to persist this Token either to database or to the session.Once user redirected back to your application you need to get back this token once you have this token use the verification_code along with this token to get Access_token like

Token accessToken = authGetAccessToken.getAccessToken((Token)   
 session.get(OAuthConstants.REQUEST_TOKEN), verifier);

,一旦你有这样的的accessToken 你喜得

希望这是有意义

EDIT1

Verification_ code为正由OAuth的系统发送,以指示用户已给定的访问,并授权有自我。这仅是握手机构的一部分。

Verification_code is being send by the OAuth system to indicate that user has given access and has authorize there self. This is only a part of handshaking mechanism.

我已通过这里提到的一页OP去就是一直有提到

i gone through the page OP has mentioned here is what has been mentioned there

$response = $this->google_oauth->get_request_token(site_url("/user/youtube_access"));
$this->_store_somewhere($response['token_secret']);

所以被要求它来存储 token_secret 在一些地方,你可以选择DB或会话什么都这样,你选择,因为这 token_secret 将被用于在稍后阶段再次重建请求

So it is being asked to store token_secret at some place, you can choose DB or session what ever way you choose as this token_secret will be used to reconstruct the request again at later stage

在我的code例如我有救整个 Request_Token 包含 token_secret 组oauth_token

in my code example i have saved whole Request_Token which contains token_secret and oauth_token

一旦用户被重定向回你的应用程序,你需要执行以下步骤

once user is redirected back to your application you need to perform the following steps

$token_secret = $this->_get_from_storage('token_secret');
 $oauth = $this->google_oauth->get_access_token(false, $token_secret);

在这里,我们撷取我们保存在最后一步,比发送要求谷歌提供的access_token的token_secret

Here we are retrieving the token_secret we saved in last step and than sending asking Google to provide access_token

我也做合格检验以及token_secret几乎同样的事情。

i am also doing almost same thing passing verifier along with token_secret

希望其明确为你

这篇关于YouTube的API请求:我怎么能得到正确的令牌(吉姆S.“code)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆