/// <summary>
/// 透過 user token 拿到 user profile
/// </summary>
/// <param name="accesstoken"></param>
/// <returns></returns>
public string GetGooogleUserInfoByAccesstoken( string accesstoken)
{
var client = new RestClient("https://www.googleapis.com/oauth2/v3/userinfo?access_token="+accesstoken);
var request = new RestRequest(new Uri("https://www.googleapis.com/oauth2/v3/userinfo?access_token=" + accesstoken), Method.Get);
try
{
var response = client.ExecuteAsync(request).Result;
if (response.IsSuccessful)
{
return response.Content;
}
else
{
return ($"Error: {response.StatusCode} - {response.ErrorMessage}");
}
}
catch (Exception ex)
{
return ("Exception occurred: " + ex.Message);
}
}
//Result
/*
{ "sub": "110525762531932290727", "name": "Hsu DMA", "given_name": "Hsu",
"family_name": "DMA", "picture":
"https://lh3.googleusercontent.com/a/ACg8ocJRBsgW_uCQGHXATIm9ODBqmNrE9gpbE7dg1qg_Od0XdfJCOL5q\u003ds96-c",
"email": "sample@gmail.com", "email_verified": true }
*/
就簡單筆記一下,方便之後自己 copy paste.
--
Before you read this, the article was in a superposition of human and AI. Upon observation, the wave function collapsed into a sleep-deprived developer.