我尝试使用access_token从Google api获取用户信息,该信息由移动端通过web api提供,但出现401错误

问题描述 投票:0回答:1

[如何通过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"
  }
}
asp.net asp.net-mvc asp.net-mvc-5 google-api asp.net-mvc-5.2
1个回答
0
投票

解决此问题:我使用了另一个API从Google获取用户信息。https://oauth2.googleapis.com/tokeninfo?id_token=Auth

© www.soinside.com 2019 - 2024. All rights reserved.