本文介绍了我的GSM Gmail插件不显示卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have built a GSM add on and published it for my domain. I built the code, on Google Apps Script and set it up in Google API Console. I installed it for my domain, but it does not show the card in Gmail It should show in the sidebar, and in the compose window. It works fine when I install the head version from within google apps script, but then I publish it to GSM for users in my organization it doesn't work. The purpose of the addon is to collect information from fields in a card and use that in an email template. I think it might be something to do with OAuth scopes but I am not sure. This is my very first GSM project and I don't know what OAuth scopes I should declare in my code and in the Google API console.

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

Here is my code, I have 2 files, appscript.json, and code.gs.code.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 [email protected] 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:

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同意屏幕页面上指定的范围在这里:

The scopes that I specify in the OAuth consent screen page are here:

个人资料

openid

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

默认情况下,电子邮件,个人资料和openid是必填项

The Email, profile, and openid are added by default and they are mandatory

这是我在GSM SDK的配置页面中指定的范围.

Here are the scopes that I specify in the configuration page of the GSM SDK.

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

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

推荐答案

您非常接近使此附加组件有效.您只需要向清单文件添加一些范围.您的最终清单应类似于以下清单:

You are very close to making this add-on works. You only need to add some scopes to your manifest file. Your final manifest should look similar to this one:

{
  "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"
      }
    }
  }
}

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

The rest of your code is correct. I deployed your add-on with this manifest, and it worked. Don't hesitate to ask any additional doubt if you need further clarification.

这篇关于我的GSM Gmail插件不显示卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:48