Skip to content

Client is unauthorized to retrieve access tokens using this method #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hakanak opened this issue Apr 10, 2017 · 1 comment
Closed

Comments

@hakanak
Copy link

hakanak commented Apr 10, 2017

Hello,
I have a problem like this:

Error Line: 83

An unhandled exception of type 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException' occurred in Google.Apis.dll

Additional information: Error:"unauthorized_client", Description:"Client is unauthorized to retrieve access tokens using this method.", Uri:""

Code:
` //UserCredential credential;
Dictionary<string, string> dictionary = new Dictionary<string, string>();
String serviceAccountEmail =
"[email protected]";

        var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);


        ServiceAccountCredential credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                
                User = "[email protected]",
                AccessMethod = new BearerToken.AuthorizationHeaderAccessMethod(),
                DefaultExponentialBackOffPolicy = Google.Apis.Http.ExponentialBackOffPolicy.UnsuccessfulResponse503,
                
                Scopes = new[] { GmailService.Scope.MailGoogleCom }
            }.FromCertificate(certificate)
        );


            // Create Gmail API service.
            var gmailService = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "MyApp",
            });

            // Define parameters of request.

            var emailListRequest = gmailService.Users.Messages.List("[email protected]");
            emailListRequest.LabelIds = "INBOX";
            emailListRequest.IncludeSpamTrash = true;
            emailListRequest.Q = "is:unread";
            emailListRequest.MaxResults = 10;

            var emailListResponse = emailListRequest.Execute();


            foreach (var item in emailListResponse.Messages)
            {
                Console.WriteLine(item.Id);
            }


        Console.Read();`
@erickoledadevrel
Copy link
Contributor

It looks like you are using the .NET client library, which is supported here:

https://developers.google.com/api-client-library/dotnet/support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants