【问题标题】:How do I use gmail api in asp.net [duplicate]如何在 asp.net 中使用 gmail api [重复]
【发布时间】:2020-02-25 19:02:14
【问题描述】:

我在我的网站上使用 gmail api 和 asp.net,但我在获取凭据时选择了 Web 客户端,但出现错误

我使用 GoogleWebAuthorizationBroker.AuthorizeAsync 但是

“错误:redirect_uri_mismatch”我得到一个错误。

如何使用。

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;
    }

【问题讨论】:

标签: asp.net asp.net-web-api gmail-api


【解决方案1】:

Web 应用程序 (ASP.NET MVC)

当您使用 ASP.NET 时,您需要在 Google API Console 中设置指向您网站的重定向 URI,这就是您获得 Error: redirect_uri_mismatch" 的原因。 Here 您可以看到一个很好的解释,说明如何为这种情况正确配置您的凭据。

ServiceAccountCredential

我认为您试图在 this way 中做更多的事情,这适用于另一种类型的实现。

【讨论】:

    猜你喜欢
    • 2018-07-17
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 2021-11-20
    • 2017-06-15
    • 2017-01-10
    相关资源
    最近更新 更多