C# Gmail API-值的格式';=获取标签google api dotnet client/1.25.0.0(gzip)和#x27;无效
我开始探索Gmail API。我按照教程显示标签列表(),效果很好 非常感谢您的帮助 当我修改程序流程时,这里给出了错误。我无法追踪错误。它给出了C# Gmail API-值的格式';=获取标签google api dotnet client/1.25.0.0(gzip)和#x27;无效,c#,.net,gmail-api,google-api-dotnet-client,C#,.net,Gmail Api,Google Api Dotnet Client,我开始探索Gmail API。我按照教程显示标签列表(),效果很好 非常感谢您的帮助 当我修改程序流程时,这里给出了错误。我无法追踪错误。它给出了Execute()方法的错误 错误:值“=获取标签”的格式 google api dotnet client/1.25.0.0(gzip)无效 这是我的密码 public static class Labels { public static void ListLabels ( ) { try {
Execute()
方法的错误
错误:值“=获取标签”的格式
google api dotnet client/1.25.0.0(gzip)无效
这是我的密码
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 ( );
}
}
这给了我一个错误。
这几乎可以肯定是由于
应用程序名“AppName=Get Labels”。
更改此项以删除空格和“=”,我怀疑此错误会消失。这几乎肯定是由于的“AppName=Get Labels”
应用程序名造成的。
更改此项以删除空格和“=”,我怀疑此错误将消失