Reputation: 821
We're integrating Google api C# SDK to our application and following Google "web application" workflow. We need to retrieve currently authenticated Google user email.
We get it works using one of these approaches:
Directly make http request to https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=xxx .
Use 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();
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;
Scopes we're using are:
"https://www.googleapis.com/auth/gmail.readonly" "email" "profile"
Examples above work well, however we don't want to use https://www.googleapis.com/auth/gmail.readonly as it's "restricted" scope.
So, we wonder if there any chance to call the Google profile email using some method from C# SDK ?
Thanks in advance, Evgeny.
Upvotes: 1
Views: 1063
Reputation: 117281
Profile
scope will give you access to google people api however i think you need to user.emails.read to get access to their email address.
https://www.googleapis.com/auth/user.emails.read View your email addresses
using a gmail scope seems like overkill if you just want the users email address. Which api are you using in general some of them have ways of getting the users email.
Upvotes: 1