[如何通过access_token从Google API获取MVC5中的用户信息,移动端将哪个令牌提供给Web API?[使用的代码] [1]:https://i.stack.imgur.com/D2hfW.png
HttpClient client = new HttpClient();
var urlProfile ="https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + model.Auth;
client.CancelPendingRequests();
HttpResponseMessage output = client.GetAsync(urlProfile).Result;
if (output.IsSuccessStatusCode)
{
string outputData = output.Content.ReadAsStringAsync().Result;
}
获取错误:如果我使用上述代码通过access_token获取用户信息
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
解决此问题:我使用了另一个API从Google获取用户信息。https://oauth2.googleapis.com/tokeninfo?id_token=Auth