【问题标题】:Want to perform Archive functionality using gmail api想要使用 gmail api 执行存档功能
【发布时间】:2016-05-27 07:23:30
【问题描述】:

我正在使用 gmail api 开发一个应用程序。 我想执行存档功能。 我已经通过 api https://developers.google.com/gmail/api 但找不到任何所需的解决方案。

谁能建议我任何解决方案。

提前致谢。

【问题讨论】:

标签: ios objective-c gmail-api


【解决方案1】:

A archived message 只是位于All Mail 中的消息(这不是实际标签)。您可以通过删除消息上的INBOX-标签(或您添加到其中的任何其他标签)来实现这一点,这可以通过modify 实现。

【讨论】:

    【解决方案2】:
      C# Code for Gmail APIs Archive email by using OAuth 2.0 service.   
         class ReadAllMails
          {       
            static string[] Scopes = { GmailService.Scope.MailGoogleCom };
            static string ApplicationName = "Gmail API .NET Quickstart";
            static void Main(string[] args)
            {
              UserCredential credential;
              using (var stream =
              new FileStream("credentials_dev.json", FileMode.Open, FileAccess.Read))
              {
                   string credPath = "token_MailGoogleCom.json";
                   credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                   GoogleClientSecrets.Load(stream).Secrets,
                   Scopes,
                   "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;                      
                 }
    
                var service = new GmailService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = ApplicationName,
                }); 
    
                List<string> lableIds = new List<string>();
                lableIds.Add("INBOX");
                ModifyMessageRequest mods = new ModifyMessageRequest();
                mods.RemoveLabelIds= lableIds;
                service.Users.Messages.Modify(mods, "me", emailId).Execute();
                //emailId that you want to archive
           }
        }
    

    【讨论】:

    • 请解释答案,而不仅仅是发布代码。
    • 我使用以下链接激活了我的 Gmail API developers.google.com/gmail/api/quickstart/dotnet。然后我使用 GmailService.User.Message.Modify 中存在的修改服务从消息中删除标签 INBOX 以将当前邮件移动到存档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-13
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多