oauth2.0用户个人资料信息 [英] oauth2.0 for user profile info
问题描述
我该如何使用oauth2.0让用户对谷歌Android应用程序配置文件信息。我需要一个Android应用程序的正确code /例子。我需要的用户喜欢的信息:
- 个人资料照片
- 生日
- 性别
- 位置
感谢
谷歌的OAuth将需要以下步骤:
1.注册与谷歌这里。注册后,在安装的应用程序后,
部分,你会得到你的 REDIRECT_URI
和 CLIENT_ID
2, REDIRECT_URI
和 CLIENT_ID
上面现在将在以下网址中使用获得的。
https://accounts.google.com/o/oauth2/auth?+ "scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile"+ &放大器; redirect_uri =+ REDIRECT_URI +&放大器; RESPONSE_TYPE = code+&放大器; CLIENT_ID =+ CLIENT_ID;
3,本网址会带你到谷歌验证页面,在这里谷歌接管并输入您的帐户资料。此外,它会被重定向至批准页面,用户可以让您的应用程序使用他们的谷歌的数据。
4.Now,对此的回应你得到 ACCESS code
从谷歌作为一个JSON或HTML页面的标题。解析 ACCESS code
。
5.具有的 ACCESS code
你现在将与以下职位数据的 POST
请求获得访问令牌
。
'code'//这是获得code
CLIENT_ID//同早先
client_secret'//你会发现这个在您注册的谷歌网页上
redirect_uri//同早先
grant_type=authorization_ code//原样
6.您现在获得访问令牌在JSON作为access_token。分析此访问令牌。
7.Make使用访问令牌来进行呼叫以下网址
<$p$p><$c$c>https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=your_access_token_here
8.您将获得用户数据,该呼叫作为JSON的响应。
下面是您可能需要额外的文档: https://developers.google.com/accounts/docs/OAuth2InstalledApp
how can i use oauth2.0 to get users google profile info on android app. I need the proper code/ example for an android app. I need the users information like :
- profile photo
- birthday
- gender
- location
Thanks
Google OAuth will require the following steps:
1.Register with Google here. after registering ,in the INSTALLED APPLICATION
section you will get your REDIRECT_URI
and CLIENT_ID
2.The REDIRECT_URI
and CLIENT_ID
obtained above now will be used in the following url.
https://accounts.google.com/o/oauth2/auth?" + "scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile"+ "&redirect_uri=" + REDIRECT_URI + "&response_type=code" +"&client_id=" + CLIENT_ID;
3.This url will take you to the Google Authentication page, here google takes over and you enter your account details. Further, it is redirected to the approval page, where the user allows your app to use their google data.
4.Now, as a response to this you get ACCESS CODE
from google as a JSON or in the title of the html page. Parse the ACCESS CODE
.
5.With the ACCESS CODE
you will now make a POST
request with the following post data to get the ACCESS TOKEN
.
'code' // this is the access code
'client_id' // same as earlier
'client_secret' // you will find this on the google page where you registered
'redirect_uri' // same as earlier
'grant_type' = "authorization_code" // as is
6.You will now get the ACCESS TOKEN in a JSON as "access_token" . parse this access token.
7.Make use of the Access token to make a call on the following url
https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=your_access_token_here
8.You will get the users data as a response to this call as a JSON.
Here are additional docs that you may need: https://developers.google.com/accounts/docs/OAuth2InstalledApp
这篇关于oauth2.0用户个人资料信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!