GMAIL API中的气体:状态变化的刷新接口?

发布于 2025-01-24 15:17:27 字数 1169 浏览 0 评论 0原文

我目前正在使用Google-Apps-scripts编写线程和消息上的标签。脚本完成后,有效载荷将移动,但是在用户与Gmail交互之前,用户前端上的显示不会更改。

有没有办法将刷新命令推向Gmail?我如何才能优雅地向用户显示“作业完成”,以便他们知道消息现在已适当标记?

我直接与Gmail API合作,而不是Gmailapp。我发现了ActionResponseBuilder.setStateChanged(),但问题是我目前不使用任何形式的前端接口。这一切都在背景中。

这是我使用的一些代码的缩写示例(按请求):

function changeLabel(ids,oldLabel,newLabel) {
  Gmail.Users.Messages.batchModify({
    "ids":ids,
    "addLabelIds":oldLabel,
    "removeLabelIds":newLabel
  },"me");
}

function start() {
  // Labels to work with
  const FOO = "Label_5095729546757874255";
  const BAR = "Label_5102306845672214551";

  // API call to retrieve list of messages by Label
  var msgIdsByLabel = new MessageIndex(FOO);  

  // API call to retrieve message contents
  var payloadMessages = new Messages(msgIdsByLabel);

  var manifestMessagesToMove = [];

  for (var i=0;i < Object.keys(payloadMessages.response).length; i++) {
    // Criteria for selecting messages to move goes here
    manifestMessagesToMove[i] = payloadMessages.response[i].id;
  }

  // Change labels of Message Ids
  changeLabel(manifestMessagesToMove,FOO,BAR);

  // ??? Refresh Gmail Interface ???
}

I'm currently writing using Google-Apps-Scripts to do change labels on threads and messages. When the script completes, the payloads are moved, but the display on the user frontend does not change until the user interacts with Gmail.

Is there a way to push a refresh command to Gmail? How can I gracefully display "job's done" to the user so they know that messages are now appropriately labeled?

I am working directly against the Gmail API, not GmailApp. I discovered ActionResponseBuilder.setStateChanged(), but the problem is I am currently not working with any sort of frontend interface. This is all in the background.

Here is an abbreviated example of some of the code I'm using to grab messages to modify (as requested):

function changeLabel(ids,oldLabel,newLabel) {
  Gmail.Users.Messages.batchModify({
    "ids":ids,
    "addLabelIds":oldLabel,
    "removeLabelIds":newLabel
  },"me");
}

function start() {
  // Labels to work with
  const FOO = "Label_5095729546757874255";
  const BAR = "Label_5102306845672214551";

  // API call to retrieve list of messages by Label
  var msgIdsByLabel = new MessageIndex(FOO);  

  // API call to retrieve message contents
  var payloadMessages = new Messages(msgIdsByLabel);

  var manifestMessagesToMove = [];

  for (var i=0;i < Object.keys(payloadMessages.response).length; i++) {
    // Criteria for selecting messages to move goes here
    manifestMessagesToMove[i] = payloadMessages.response[i].id;
  }

  // Change labels of Message Ids
  changeLabel(manifestMessagesToMove,FOO,BAR);

  // ??? Refresh Gmail Interface ???
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2025-01-31 15:17:27

不幸的是,这是不可能的。

Gmail UI不能从应用程序脚本中刷新,因为它是在云中运行的,作为与用户在Web浏览器中查看的脚本的单独会话。两者没有连接 - Gmail API也是如此。

如果您没有前端接口(又称使用cardService的Gmail附加组件),那么也没有一种向用户显示消息的方法。刷新将必须手动完成。

Unfortunately this isn't possible.

The Gmail UI can't be refreshed from Apps Script as it is run in the cloud as a separate session to that which is being viewed in the web browser by a user. The two aren't connected - and the same goes for the Gmail API.

If you don't have a front-end interface (aka a Gmail Add-on utilising CardService) then there is not a way of displaying a message to the user, either. The refresh will have to be done manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文