C# 允许通过Google Gmail API阅读电子邮件

C# 允许通过Google Gmail API阅读电子邮件,c#,asp.net-mvc,gmail,google-apps,google-authentication,C#,Asp.net Mvc,Gmail,Google Apps,Google Authentication,嗨,我想阅读所有的电子邮件,我创建了一个谷歌应用程序,如下所示 现在我正在通过以下代码进行测试 public async Task ListLabels() { UserCredential credential = null; ; using (var stream = new FileStream("client_secret_899062187155-oog0nddbvujerg5pdklp24clt25rg9ut.apps

嗨,我想阅读所有的电子邮件,我创建了一个谷歌应用程序,如下所示

现在我正在通过以下代码进行测试

public async Task ListLabels()
        {
            UserCredential credential = null; ;
            using (var stream = new FileStream("client_secret_899062187155-oog0nddbvujerg5pdklp24clt25rg9ut.apps.googleusercontent.com.json", FileMode.Open, FileAccess.Read))
            {
                credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
                    new[] { GmailService.Scope.GmailReadonly },
                    "user", CancellationToken.None);
            }

            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Gmail Test",
            });

            try
            {
                ListLabelsResponse response = service.Users.Labels.List("me").Execute();
                foreach (Label label in response.Labels.OrderBy(p => p.Name))
                {
                    Console.WriteLine(label.Id + " - " + label.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
            }
        }
现在,一旦我登录,我得到一个错误


我无法确定需要设置哪个重定向URL。

在创建项目时,选择应用程序类型为“其他”,然后创建您的凭据即可: