0
我有一個應用程序使用的API,應用程序向我發送了已經過身份驗證的用戶或Google帳戶的id_token。如何通過API調用從id_token獲取用戶配置文件
如何在ASP.net中向API API調用API調用(而不是Java腳本調用)以獲取用戶配置文件信息(如名稱),以便將用戶保存在應用程序的數據庫中。
我已經有一個谷歌項目與客戶端ID和客戶端的祕密。
我有一個應用程序使用的API,應用程序向我發送了已經過身份驗證的用戶或Google帳戶的id_token。如何通過API調用從id_token獲取用戶配置文件
如何在ASP.net中向API API調用API調用(而不是Java腳本調用)以獲取用戶配置文件信息(如名稱),以便將用戶保存在應用程序的數據庫中。
我已經有一個谷歌項目與客戶端ID和客戶端的祕密。
所以我找到了一種方法,雖然asp.net API獲取我想要的用戶信息。
using (var client = new System.Net.WebClient())
{
var uri = new Uri("https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + ACCESSTOKENFROMLOGGININ + "&access_type=offline");
var response = client.DownloadString(uri);
}
you response will have these fields
{
"issued_to": "",
"audience": "",
"user_id": "",
"scope": "",
"expires_in": 756,
"email": "",
"verified_email": true,
"access_type": "online"
}
Then you could make another call to get more personal information
var userInfoUri = new Uri("https://www.googleapis.com/oauth2/v2/userinfo");
var userInfoClient = new System.Net.WebClient();
client.Headers.Add("Authorization", "Bearer " + YOUACCESSToken);
and you will receive an object like this
{
"id": "",
"name": "",
"given_name": "",
"family_name": "",
"link": "",
"picture": "",`enter code here`
"locale": "en"
}