我创建了谷歌api服务应用程序,并验证默认情况下添加了user.profile信息范围。
身份验证,令牌和获取用户信息对我来说工作正常,但获取用户信息api响应中缺少少量字段。
我使用下面提到的端点与谷歌API进行通信。
WebRequest request = WebRequest.Create(googleGetUrl + $"&access_token={accesstoken}");
request.Credentials = CredentialCache.DefaultCredentials;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream receiveStream = response.GetResponseStream())
{
using (StreamReader readStream = new StreamReader(receiveStream))
{
string responseFromServer = readStream.ReadToEnd();
return JsonConvert.DeserializeObject<GoogleUser>(responseFromServer);
}
}
}
我得到了如下所述的json响应
{
id: "xxxxxxxxxxxxx",
email: "[email protected]",
verified_email: true,
picture: "https://validurl/photo.jpg",
hd: "getting value"
}
但是我想要的就像下面提到的Json
{
id: "xxxxxxxxxxxxx",
email: "[email protected]",
verified_email: true,
picture: "https://validurl/photo.jpg",
hd: "getting value",
name: "some value",
family_name: "some value",
given_name: "some value"
}
范围配置:
如果我错过任何配置,请告诉我。非常感谢您的帮助。
亲切的问候,Mohsin
来自userinfo端点的响应不是标准,所有oauth服务器都有自己的返回内容实现。如果你想获得更多信息,你应该尝试people api。除非您请求电子邮件范围,否则任何人都不应该回复几年前google停止返回verified_email我认为。
GET /v1/people/me HTTP/1.1
Host: people.googleapis.com
Content-length: 0
Authorization: Bearer aJxKQvzgCj5fa86EbB_AYqjt-
我在身份验证URL中缺少范围参数,并使用下面的URL为我工作。
return string.Format(“https://accounts.google.com/o/oauth2/auth?client_id= {0}&redirect_uri = {1}&response_type = code&scope = {2}”,ClientId,CallBackUrl,“https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email”);
亲切的问候,Mohsin Pathan