简体   繁体   English

如何使用谷歌获取用户的 email 地址 Oauth api

[英]How to get user's email address using google Oauth api

I am using with Google's OAuth 2.0 Playground using my own personal Google account, but I cannot seem to recover my Gmail address using the playground.我正在使用我自己的个人 Google 帐户使用 Google 的 OAuth 2.0 Playground,但我似乎无法使用 Playground 恢复我的 Gmail 地址。 I am using the api url https://www.googleapis.com/oauth2/v3/userinfo .我正在使用 api url https://www.googleapis.com/oauth2/v3/userinfo But didn't get email address.但是没有得到 email 地址。 I get various information about the user such as family name, first name, gender, picture, etc. I have referred with Google OAuth API to get user's email address?我得到了有关用户的各种信息,例如姓氏、名字、性别、照片等。我参考了Google OAuth API 以获取用户的 email 地址? but it didn't work.但它没有用。 I am using the code(c#-windows form) below(to get email address & user information)我正在使用下面的代码(c#-windows 表单)(获取 email 地址和用户信息)

string userinfoRequestURI = "https://www.googleapis.com/oauth2/v3/userinfo
HttpWebRequest userinfoRequest = (HttpWebRequest)WebRequest.Create(userinfoRequestURI);
userinfoRequest.Method = "GET";
userinfoRequest.Headers.Add(string.Format("Authorization: Bearer {0}", access_token));
userinfoRequest.ContentType = "application/x-www-form-urlencoded";
userinfoRequest.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

WebResponse userinfoResponse = await userinfoRequest.GetResponseAsync();
//userinfoResponse.
using (StreamReader userinfoResponseReader = new StreamReader(userinfoResponse.GetResponseStream()))
{
    // reads response body
    string userinfoResponseText = await userinfoResponseReader.ReadToEndAsync();
    output(userinfoResponseText);
}

When you authorized your request over on oauth playground, make sure you sent email.当您在 oauth 操场上授权您的请求时,请确保您发送了 email。

If you did send the email scope then i recommend going though the People api rather then the userinfo endpoint, but remember to add the profile scope and the email scopes If you did send the email scope then i recommend going though the People api rather then the userinfo endpoint, but remember to add the profile scope and the email scopes

The userinfo endpoint is not guaranteed to return the claims every time.不保证 userinfo 端点每次都返回声明。 Its better to go though the People api for that.最好是 go 尽管人们 api 为此。

Tip: consider looking into the google api .net client library.提示:考虑查看 google api .net 客户端库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Google Oauth .NET 库获取用户的 email 地址 - How to get email address of a user using Google Oauth .NET library 使用C#和OAuth从Twitter获取用户的电子邮件地址 - Get user's email address from Twitter with C# and OAuth 如何使用twitter api获取twitter用户的电子邮件地址 - How to get the email address of twitter user with twitter api 如何使用 Microsoft Graph sdk 通过 email 地址从 Active Directory 获取用户信息 - How to get user's information from Active Directory by email address using Microsoft Graph sdk 如何在C#中获取当前用户的电子邮件地址和密码 - How to get Current User's Email address and password in C# 在C#中使用google OAuth2后如何获得email? - how to get email after using google OAuth2 in C#? 如何在没有Graph API的C#Azure B2C身份验证中获取当前登录用户的用户名和电子邮件地址? - How to get current login user's username & email address in C# Azure B2C authentication without Graph API? 我可以使用此逻辑来获取Google帐户的电子邮件地址(使用Google+ API(人)) - May I use this logic to get the Google Account email address (using Google+ API (People) ) 获取登录用户的电子邮件地址并将其传递给电子邮件 - Get logged in user's email address and pass it in an email message C#Google OAuth2获取当前登录用户的电子邮件 - C# Google OAuth2 get email of the user currently login
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM