无法起草回复。权限错误

时间:2018-05-10 12:44:20

标签: gmail-addons

我遵循了官方指南https://developers.google.com/gmail/add-ons/how-tos/composehttps://developers.google.com/gmail/add-ons/guides/quickstart

这是我的appsscript.json:

{
  "oauthScopes": [
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/gmail.addons.current.action.compose"
  ],
  "gmail": {
    "name": "Gmail Add-on Quickstart",
    "logoUrl": "https://www.gstatic.com/images/icons/material/system/2x/bookmark_black_24dp.png",
    "contextualTriggers": [{
      "unconditional": {
      },
      "onTriggerFunction": "createReplyDraft"
    }],
    "openLinkUrlPrefixes": [
      "https://mail.google.com/"
    ],
    "primaryColor": "#4285F4",
    "secondaryColor": "#4285F4"
  }
}

和Code.gs:

  var composeAction = CardService.newAction()
      .setFunctionName('createReplyDraft');
  var composeButton = CardService.newTextButton()
      .setText('Compose Reply')
      .setComposeAction(composeAction, CardService.ComposedEmailType.REPLY_AS_DRAFT);

  // ...




  /**
   *  Creates a draft email (with an attachment and inline image)
   *  as a reply to an existing message.
   *  @param {Object} e data passed by the compose action.
   *  @return {ComposeActionResponse}
   */
  function createReplyDraft(e) {
    // Activate temporary Gmail add-on scopes, in this case to allow
    // a reply to be drafted.
    var accessToken = e.messageMetadata.accessToken;
    GmailApp.setCurrentMessageAccessToken(accessToken);

    // Creates a draft reply.
    var messageId = e.messageMetadata.messageId;
    var message = GmailApp.getMessageById(messageId);
    var draft = message.createDraftReply('',
        {
            htmlBody: "Kitten!"
        }
    );

    // Return a built draft response. This causes Gmail to present a
    // compose window to the user, pre-filled with the content specified
    // above.
    return CardService.newComposeActionResponseBuilder()
        .setGmailDraft(draft).build();
  }

我想打开Gmail的“回复”面板并将一些内容粘贴到其中。

错误跟随错误:使用加载项。 运行时错误。 访问被拒绝::无法在没有用户交互的情况下进行组合.. [line:27,function:createReplyDraft,file:Code]

我已多次重新安装模块,并尝试授予“https://mail.google.com/”的全范围权限。

3 个答案:

答案 0 :(得分:1)

查看您的代码,似乎您在尝试加载加载项后立即尝试调用CreateReplyDraft函数。 Google不允许这样做,用户必须单击UI中的按钮来跟踪草稿的创建。

答案 1 :(得分:0)

您是否尝试过将 https://www.googleapis.com/auth/gmail.readonly 添加到您的范围内?

答案 2 :(得分:0)

你不能直接触发这样的动作。您必须创建一个按钮小部件,它将compose action(您的createReplyDraft函数)与其链接在一起。因此,当用户点击该按钮时,将触发撰写动作。