0

我想知道如何使用来自 Google API 的访问令牌获取用户详细信息、名字、姓氏和电子邮件 ID。目前,我正在使用以下代码返回我

{ "error": "invalid_grant", "error_description": "Bad Request" },

使用 RestSharp 的服务器端 c# 代码

var client = new RestClient("https://oauth2.googleapis.com/token");
var request = new RestRequest(Method.POST);
request.AddParameter("code", accessToken);
request.AddParameter("redirect_uri", "[my domain ]/oauth?provider=google");
request.AddParameter("client_id", "[ClientId]");
request.AddParameter("client_secret", "[ClientSecret]");
request.AddParameter("scope", "openid email profile");
request.AddParameter("grant_type", "authorization_code");

IRestResponse response = client.Execute(request);

OAuth consent screenGoogle 控制台中,我没有在Scopes. 这会是个问题吗?我只访问基本信息。另外,我不确定要添加哪些范围。

在此先感谢并感谢您对此的任何帮助。

更新:我尝试添加这个范围 - https://www.googleapis.com/auth/userinfo.profile但它仍然是同样的问题。

这是我的流量。我在页面上有这个链接

https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=<Redirect url>?provider=google&prompt=consent&response_type=code&client_id=<Client id>&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+openid&access_type=offline

单击此链接后,用户将被重定向到 Google 身份验证页面。一旦通过身份验证,它就会使用访问令牌重定向到重定向 URL,然后在服务器端进行验证并获取用户信息。

4

0 回答 0