I tried to use Google .NET API to get verified user email, but app stops responding in line I marked with ****. The first time I run it opens browser and asks for my GMAIL, after selecting gmail it says now you can close browser window, but my desktop app will stop responding. Next time I run app it just stops responding unless I delete Google.Apis.Auth
folder from AppData\Roaming
:
private async Task VerifyEmail()
{
UserCredential credential;
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "xxxx.apps.googleusercontent.com",
ClientSecret = "xxxx-xxxxx"
},
new[] { Google.Apis.Oauth2.v2.Oauth2Service.Scope.UserinfoEmail },
"user",
CancellationToken.None,
new FileDataStore("My.DataStore")
);
var initializer =
new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My App",
};
var oauthSerivce = new Google.Apis.Oauth2.v2.Oauth2Service(initializer);
// app stops responding here **** :
var userInfo = await oauthSerivce.Userinfo.Get().ExecuteAsync();
MessageBox.Show(userInfo.Email);
}