如何从 google sheet 获取数据到我的 Gmail 插件
How to get data from google sheet to my Gmail addon
我试图从 google sheet 获取一些数据并将其显示在 Gmail 插件中。
当我尝试 运行 getValue() 函数时,出现如下错误。
You do not have permission to call openById (line 29, file "Code")Dismiss
这是我的code.gs文件代码
function createWidgetCard() {
return CardService
.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Widget demonstration')
.setSubtitle('Check out these widgets')
.setImageStyle(CardService.ImageStyle.SQUARE)
.setImageUrl(
'https://www.example.com/images/headerImage.png'))
.addSection(
CardService.newCardSection()
.setHeader('Simple widgets') // optional
.addWidget(CardService.newTextParagraph().setText(
'These widgets are display-only. ' +
'A text paragraph can have multiple lines and ' +
getValue()))
.addWidget(CardService.newImage().setImageUrl(
'https://www.example.com/images/mapsImage.png')))
.addCardAction(CardService.newCardAction().setText('Gmail').setOpenLink(
CardService.newOpenLink().setUrl('https://mail.google.com/mail')))
.build();
}
//get data from sheet
function getValue(){
var ss = SpreadsheetApp.openById("181tnith14lu8ttAvtqsU3gHi32-UjcrPqH5Pjuenk5A");
var sheet = ss.getSheets()[0];
var lastRaw = sheet.getLastRow();
var text = sheet.getRange(lastRaw, 3.0).getValue();
Logger.log("text");
return text;
}
这是我的清单文件代码(appscript.json)
{
"oauthScopes": [
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/script.storage",
"https://www.googleapis.com/auth/script.external_request"
],
"gmail": {
"name": "Finetech Addon",
"logoUrl": "https://www.gstatic.com/images/icons/material/system/2x/bookmark_black_24dp.png",
"contextualTriggers": [{
"unconditional": {
},
"onTriggerFunction": "createWidgetCard"
}],
"openLinkUrlPrefixes": [
"https://mail.google.com/"
],
"primaryColor": "#4285F4",
"secondaryColor": "#4285F4",
"version": "TRUSTED_TESTER_V2"
}
}
我的要求是访问 sheet 并获取一些数据并将其显示在 Gmail 插件上。如果有人能提供正确的代码截图,那将非常有帮助。
我认为需要将电子表格的使用范围添加到清单的 "oauthScopes" 中。所以请在appsscript.json
中添加https://www.googleapis.com/auth/spreadsheets
到"oauthScopes"。然后重试。
如果这不起作用,我很抱歉。
我试图从 google sheet 获取一些数据并将其显示在 Gmail 插件中。 当我尝试 运行 getValue() 函数时,出现如下错误。
You do not have permission to call openById (line 29, file "Code")Dismiss
这是我的code.gs文件代码
function createWidgetCard() {
return CardService
.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Widget demonstration')
.setSubtitle('Check out these widgets')
.setImageStyle(CardService.ImageStyle.SQUARE)
.setImageUrl(
'https://www.example.com/images/headerImage.png'))
.addSection(
CardService.newCardSection()
.setHeader('Simple widgets') // optional
.addWidget(CardService.newTextParagraph().setText(
'These widgets are display-only. ' +
'A text paragraph can have multiple lines and ' +
getValue()))
.addWidget(CardService.newImage().setImageUrl(
'https://www.example.com/images/mapsImage.png')))
.addCardAction(CardService.newCardAction().setText('Gmail').setOpenLink(
CardService.newOpenLink().setUrl('https://mail.google.com/mail')))
.build();
}
//get data from sheet
function getValue(){
var ss = SpreadsheetApp.openById("181tnith14lu8ttAvtqsU3gHi32-UjcrPqH5Pjuenk5A");
var sheet = ss.getSheets()[0];
var lastRaw = sheet.getLastRow();
var text = sheet.getRange(lastRaw, 3.0).getValue();
Logger.log("text");
return text;
}
这是我的清单文件代码(appscript.json)
{
"oauthScopes": [
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/script.storage",
"https://www.googleapis.com/auth/script.external_request"
],
"gmail": {
"name": "Finetech Addon",
"logoUrl": "https://www.gstatic.com/images/icons/material/system/2x/bookmark_black_24dp.png",
"contextualTriggers": [{
"unconditional": {
},
"onTriggerFunction": "createWidgetCard"
}],
"openLinkUrlPrefixes": [
"https://mail.google.com/"
],
"primaryColor": "#4285F4",
"secondaryColor": "#4285F4",
"version": "TRUSTED_TESTER_V2"
}
}
我的要求是访问 sheet 并获取一些数据并将其显示在 Gmail 插件上。如果有人能提供正确的代码截图,那将非常有帮助。
我认为需要将电子表格的使用范围添加到清单的 "oauthScopes" 中。所以请在appsscript.json
中添加https://www.googleapis.com/auth/spreadsheets
到"oauthScopes"。然后重试。
如果这不起作用,我很抱歉。