[英]How to get access token using authorization code?
I am trying to develop an app which requires gmail authorization and authentication. 我正在尝试开发需要gmail授权和身份验证的应用。 using oAuth2 i have retrieved the authorization code but now how can i get the access token using this code...?? 使用oAuth2,我已经检索了授权代码,但是现在如何使用此代码获取访问令牌...? I am using javascript and html5 for this app. 我正在为此应用程序使用javascript和html5。
We need to send Post request which will include all the parameters like : client_secret, client_id, grant_type and code. 我们需要发送Post请求,其中将包含所有参数,例如:client_secret,client_id,grant_type和代码。 Since my app is Windows 8 based,so before sending POST request you need to encode your parameters otherwise you wont get the token. 由于我的应用程序基于Windows 8,因此在发送POST请求之前,您需要对参数进行编码,否则您将无法获得令牌。
Hi all i have got answer to my question. 大家好,我已经回答了我的问题。
After getting success code, you need to Use encodeURIComponent to encode each and every field in the query and then send the post request. 获取成功代码后,您需要使用encodeURIComponent对查询中的每个字段进行编码,然后发送发布请求。
eg - var post_data = 'client_id=' + encodeURIComponent(CLIENTID) + '&redirect_uri=' + encodeURIComponent(REDIRECT) + '&code=' + encodeURIComponent(CODE) + '&grant_type=' + encodeURIComponent(GRANT_TYPE) + '&client_secret=' + encodeURIComponent(CLIENT_SECRET); 例如-var post_data ='client_id ='+ encodeURIComponent(CLIENTID)+'&redirect_uri ='+ encodeURIComponent(REDIRECT)+'&code ='+ encodeURIComponent(CODE)+'&grant_type ='+ encodeURIComponent(GRANT_TYPE)+'&client_secret ='+ encodeURIComponent(CLIENT_SECRET);
and u need to assign this to the data field in your post request. 您需要将其分配给您的发帖请求中的数据字段。
Then only , you will be able to get the access_token. 然后只有,您将能够获得access_token。 I have used this code in my metro app and now i am able to successfully log into my gmail account via my application. 我已经在Metro应用中使用了此代码,现在我可以通过我的应用成功登录到Gmail帐户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.