Exemple #1
0
        private async Task iniciarSesionAsync()
        {
            var secrets = new ClientSecrets {
                ClientId = "338943711113-vevkfkdq9rtfd84q8isbsj6nq2dssvci.apps.googleusercontent.com", ClientSecret = "3nHVlB5FtNYvFVeXcEbpQ0vR"
            };

            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, new[] { DriveService.Scope.Drive }, "user", CancellationToken.None);

            if (credential.Token.IsExpired(credential.Flow.Clock))
            {
                try
                {
                    if (credential.RefreshTokenAsync(CancellationToken.None).Result)
                    {
                        MessageBox.Show("Token refrescado");
                        Calendario cal = new Calendario();
                        cal.credentials = credential;
                        cal.Show();
                        timer1.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("El token expiro pero no se pudo refrescar,por favor volver a iniciar sesion");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {
                Calendario cal = new Calendario();
                cal.credentials = credential;
                cal.Show();
                timer1.Enabled = true;
            }
        }