0

我已经为我的域构建了一个 GSM 插件并发布了它。我在 Google Apps Script 上构建了代码,并在 Google API Console 中进行了设置。我为我的域安装了它,但它没有在 Gmail 中显示卡片 它应该显示在侧边栏和撰写窗口中。当我从 google 应用程序脚本中安装 head 版本时它工作正常,但是我将它发布到 GSM 以供我组织中的用户使用它不起作用。该插件的目的是从卡片中的字段收集信息并在电子邮件模板中使用这些信息。我认为这可能与 OAuth 范围有关,但我不确定。这是我的第一个 GSM 项目,我不知道应该在我的代码和 Google API 控制台中声明什么 OAuth 范围。

这是我的代码,我有 2 个文件,appscript.json 和 code.gs。代码.gs:

function onGmailCompose(e) {
  console.log(e);
  var header = CardService.newCardHeader()
      .setTitle('Use Template')
      .setSubtitle('Use the template for sending an email after a review has been published.');
  // Create text input for entering the cat's message.
  var input2 = CardService.newTextInput()
  .setFieldName('FName')
  .setTitle('First Name')
  .setHint('What is the readers first name?');
  var input3 = CardService.newTextInput()
  .setFieldName('BookTitle')
  .setTitle('Reviewed Book Title')
  .setHint('What is the title of the book reviewed?');
  var input4 = CardService.newTextInput()
  .setFieldName('BookAuthor')
  .setTitle('Reviewed Book Author')
  .setHint('Who is the author of the book reviewed?');
  // Create a button that inserts the cat image when pressed.
  var action = CardService.newAction()
      .setFunctionName('useTemplate');
  var button = CardService.newTextButton()
      .setText('Use Template')
      .setOnClickAction(action)
      .setTextButtonStyle(CardService.TextButtonStyle.FILLED);
  var buttonSet = CardService.newButtonSet()
      .addButton(button);
  // Assemble the widgets and return the card.
  var section = CardService.newCardSection()
      .addWidget(input2)
      .addWidget(input3)
      .addWidget(input4)
      .addWidget(buttonSet);
  var card = CardService.newCardBuilder()
      .setHeader(header)
      .addSection(section);
  return card.build();
}
function useTemplate(e) {
  console.log(e);
  var FName = e.formInput.FName;
  var Title = e.formInput.BookTitle;
  var Author = e.formInput.BookAuthor;
  var now = new Date();
  var htmlIntro = '<p>Hello, ';
var html2 = ' Thank you for writing a book review at <a href="https://www.goodbookreviews.page">Good Book Reviews</a> on ';
var html3 = ' by ';
var html4 = '. You Review has been published to our site. Any personal information you included was NOT published, including first name, last name,  age, and email address. Only info you wrote about the book was published. You can see it right <a href="https://www.goodbookreviews.page./books-and-reviews/look-at-reviews"> here!</a> If you need anything else, feel free to contact us at support@goodbookreviews.page or reply to this email to contact us. <br> Happy Reading,<br> The Book Review Team</p>';
var message = htmlIntro + FName + html2 + Title + html3 + Author + html4;
  var response = CardService.newUpdateDraftActionResponseBuilder()
  .setUpdateDraftBodyAction(CardService.newUpdateDraftBodyAction()
                            .addUpdateContent(message, CardService.ContentType.MUTABLE_HTML)
                            .setUpdateType(CardService.UpdateDraftBodyType.IN_PLACE_INSERT))
  .build();
  return response;
}
function onGmailMessage(e) {
  console.log(e);
  var header = CardService.newCardHeader()
  .setTitle('Unavailable')
  .setSubtitle('Open the compose window to use template');
  var card = CardService.newCardBuilder()
  .setHeader(header);
  return card.build();
}

appscript.json:

{
  "timeZone": "America/Chicago",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
   "oauthScopes": ["https://www.googleapis.com/auth/gmail.compose"],
  "runtimeVersion": "V8",
  "addOns": {
    "common": {
      "name": "Review Published Email Template",
      "logoUrl": "https://goodbookreviews.page/Logo.png",
      "useLocaleFromApp": true,
      "universalActions": [{
        "label": "Book Review ",
        "openLink": "https://www.goodbookreviews.page"
      }]
    },
    "gmail": {
      "contextualTriggers": [{
        "unconditional": {
        },
        "onTriggerFunction": "onGmailMessage"
      }],
      "composeTrigger": {
        "selectActions": [{
          "text": "Use Template",
          "runFunction": "onGmailCompose"
        }],
        "draftAccess": "NONE"
      }
    }
  }
}

我在 OAuth 同意屏幕页面中指定的范围如下:

电子邮件

轮廓

打开ID

https://www.googleapis.com/auth/gmail.compose

Email、profile 和 openid 是默认添加的,它们是强制性的

以下是我在 GSM SDK 的配置页面中指定的范围。

https://www.googleapis.com/auth/userinfo.email

https://www.googleapis.com/auth/userinfo.profile

https://www.googleapis.com/auth/gmail.compose

4

1 回答 1

0

您非常接近使此附加组件正常工作。您只需要在清单文件中添加一些范围。您的最终清单应与此类似:

{
  "timeZone":"America/Chicago",
  "dependencies":{

  },
  "exceptionLogging":"STACKDRIVER",
  "oauthScopes":[
    "https://www.googleapis.com/auth/gmail.compose",
    "https://www.googleapis.com/auth/gmail.addons.current.action.compose",
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/script.locale"
  ],
  "runtimeVersion":"V8",
  "addOns":{
    "common":{
      "name":"Review Published Email Template",
      "logoUrl":"https://goodbookreviews.page/Logo.png",
      "useLocaleFromApp":true,
      "universalActions":[
        {
          "label":"Book Review ",
          "openLink":"https://www.goodbookreviews.page"
        }
      ]
    },
    "gmail":{
      "contextualTriggers":[
        {
          "unconditional":{

          },
          "onTriggerFunction":"onGmailMessage"
        }
      ],
      "composeTrigger":{
        "selectActions":[
          {
            "text":"Use Template",
            "runFunction":"onGmailCompose"
          }
        ],
        "draftAccess":"NONE"
      }
    }
  }
}

您的其余代码是正确的。我使用此清单部署了您的附加组件,并且它有效。如果您需要进一步澄清,请随时提出任何其他疑问。

于 2020-06-09T06:46:58.860 回答