I am trying to use the Google+ Sign-in API in ASP.NET using this code:
var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = secrets,
Scopes = new string[] { PlusService.Scope.PlusLogin }
});
token = flow.ExchangeCodeForTokenAsync("me", code, "postmessage", CancellationToken.None).Result;
var service = new Oauth2Service(new Google.Apis.Services.BaseClientService.Initializer());
var request = service.Tokeninfo();
request.AccessToken = token.AccessToken;
var info = request.Execute();
// info.Email is null here
As stated the Email
field at info
is null. If I add anything else to the Scopes
like "email" or "https://www.googleapis.com/auth/plus.profile.emails.read" (reference) I get "invalid_scope"
Leaving it to people:get API (reference) to get the emails is not any better:
var credential = new UserCredential(flow, info.UserId, token);
plusService = new PlusService(new Google.Apis.Services.BaseClientService.Initializer()
{
ApplicationName = "Test",
HttpClientInitializer = credential
});
var me = plusService.People.Get("me").Execute();
// me.Emails is null
What am I missing here?