gpt4 book ai didi

c# - Gmail API - 值 '= Get Labels google-api-dotnet-client/1.25.0.0 (gzip)' 的格式无效

转载 作者:太空宇宙 更新时间:2023-11-03 21:02:53 25 4
gpt4 key购买 nike

我开始探索 Gmail API。我按照教程显示标签列表 ( https://developers.google.com/gmail/api/quickstart/dotnet ),并且工作正常。

HELP is highly appreciated

当我修改程序流程时,这里给出了错误。我无法追踪错误。它在 Execute() 方法上给我错误。

Error: The format of value '= Get Labels google-api-dotnet-client/1.25.0.0 (gzip)' is invalid

这是我的代码。

public static class Labels
{
public static void ListLabels ( )
{
try
{
var scope = new [] { GmailService.Scope.GmailReadonly };
var service = Authorization.GetGmailService(scope, "AppName = Get Labels");

if (service != null)
{
var requestListLabels = service.Users.Labels.List("me");

var labelsList = requestListLabels.Execute().Labels;

Console .WriteLine ( "\n\n---- Labels List ----" );
if ( labelsList != null && labelsList .Count > 0 )
{
foreach ( var label in labelsList )
{
Console .WriteLine ( "{0}", label .Name );
}
}
else
{
Console .WriteLine ( "No labels available." );
}
}
else
{
Console.WriteLine("Gmail service not available.");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
}


public class Authorization
{
public object GmailAuth2 ( string[] scopes )
{
try
{
using ( var stream = new FileStream ( "Secrets/client_secret.json", FileMode .Open, FileAccess .Read ) )
{
var clientsecrets = GoogleClientSecrets .Load ( stream ) .Secrets;

var creds = GoogleWebAuthorizationBroker .AuthorizeAsync (
clientsecrets,
scopes,
"user",
CancellationToken .None,
new FileDataStore(this.GetType().ToString())
) .Result;

return creds;
}
}
catch ( Exception ex )
{
return ex .Message;
}
}

public static GmailService GetGmailService(string[] scopes, string appname)
{
try
{
var authproblem = new Authorization().GmailAuth2(scopes);
if (authproblem is string)
{
Console.WriteLine(authproblem);
return null;
}
var srvc = new GmailService(new BaseClientService.Initializer
{
HttpClientInitializer = (UserCredential)authproblem,
ApplicationName = appname
});
return srvc;
}
catch (Exception e)
{
Console.WriteLine(e);
return null;
}
}
}

这是主函数

class GmailMailBox
{
static void Main ( string [ ] args )
{
Labels.ListLabels();

Console .WriteLine ( "Press key to exit ..." );
Console .Read ( );
}
}

给我这个错误。 error picture

最佳答案

这几乎可以肯定是由于 "AppName = Get Labels" 应用程序名称。更改此设置以删除空格和“=”,我怀疑此错误会消失。

关于c# - Gmail API - 值 '= Get Labels google-api-dotnet-client/1.25.0.0 (gzip)' 的格式无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43518129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com