-6

I'm using gmail api on my site with asp.net but I chose web client when getting credential but I get error

I use GoogleWebAuthorizationBroker.AuthorizeAsync but

"Error: redirect_uri_mismatch" I get an error.

How do i use.

UserCredential credential; try{

        using (var stream = new FileStream(json, FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                new[] { GmailService.Scope.GmailReadonly, GmailService.Scope.MailGoogleCom, GmailService.Scope.GmailModify },
                v1,
                CancellationToken.None,
                new FileDataStore(uygulamaAdi)
                );
        }
        var gmailService = new GmailService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = uygulamaAdi
        });
        return gmailService;
    }
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
mr.ahmet
  • 1
  • 1

1 Answers1

0

Web applications (ASP.NET MVC)

When you use ASP.NET you need to set the redirect URI to your site in the Google API Console, that's the reason why you're getting Error: redirect_uri_mismatch". Here you can see a nice explanation on how to configure properly your credentials for this case.

ServiceAccountCredential

I think you were trying to do it more in this way, which works for another type of implementation.

alberto vielma
  • 2,302
  • 2
  • 8
  • 15