【发布时间】:2021-01-16 10:49:12
【问题描述】:
我们正在将 Google api C# SDK 集成到我们的应用程序中,并遵循 Google“网络应用程序”工作流程。 我们需要检索当前经过身份验证的 Google 用户电子邮件。
我们使用以下方法之一让它工作:
-
直接向https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=xxx发起http请求。
-
使用 Google people api C# sdk
var peopleService = new PeopleServiceService(new BaseClientService.Initializer { HttpClientInitializer = result.Credential, ApplicationName = "Test App" });
var peopleRequest = peopleService.People.Get("people/me");
peopleRequest.RequestMaskIncludeField = new List<string> { "person.EmailAddresses" };
var profile = peopleRequest.Execute();
- 使用 Google Gmail api C# sdk
var gmailService = new Google.Apis.Gmail.v1.GmailService(new BaseClientService.Initializer
{
HttpClientInitializer = result.Credential, ApplicationName = "Test App"
});
var gmailProfile = gmailService.Users.GetProfile("me").Execute();
var userGmailEmail = gmailProfile.EmailAddress;
我们使用的范围是:
“https://www.googleapis.com/auth/gmail.readonly”“电子邮件”“个人资料”
上述示例运行良好,但我们不想使用 https://www.googleapis.com/auth/gmail.readonly,因为它是“受限”范围。
所以,我们想知道是否有机会使用 C# SDK 中的某种方法调用 Google 个人资料电子邮件?
提前致谢, 叶夫根尼。
【问题讨论】:
标签: c# .net google-api google-api-dotnet-client google-people-api