如何使用 Gmail 应用程序的访问令牌?
How to use access tokens for Gmail apps?
我正在尝试创建一个 Gmail 附加范围 access token,我目前的目标是以某种方式在电子表格中获取所选邮件的附件和内容。
function onGmailDo(e) {
var sheet = SpreadsheetApp.openByUrl(
"https://docs.google.com/spreadsheets/d/14qsqQqHWQyVdbK-0LyBSac6eNqVZB1C0QxjE4xeBK_o/edit#gid=0"
);
var accessToken = e.messageMetadata.accessToken;
var messageId = e.messageMetadata.messageId;
GmailApp.setCurrentMessageAccessToken(accessToken);
var mailMessage = GmailApp.getMessageById(messageId);
var threads = GmailApp.getInboxThreads(0, 100);
var attachmentDetails = [];
var attachments = mailMessage.getAttachments();
for (var k = 0; k < attachments.length; k++) {
attachmentDetails.push(
"${attachments[k].getName()} :${attachments[k].getSize()}"
);
}
sheet.appendRow([
mailMessage.getSubject(),
mailMessage.getDate(),
mailMessage.getFrom(),
attachmentDetails.join("\n"),
]);
}
缺少一些有用的服务。此外,出于授权目的,我还必须在我的清单文件中包含以下范围。
范围:“https://mail.google.com/”、“https://www.googleapis.com/auth/spreadsheets”
更正后的代码:
function onGmailDo(e) {
console.log(e);
var text = e.parameters.text;
var isHomepage = e.parameters.isHomepage === 'true';
var card = createCard(text, isHomepage);
var navigation = CardService.newNavigation()
.updateCard(card);
var actionResponse = CardService.newActionResponseBuilder()
.setNavigation(navigation);
var sheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/14qsqQqHWQyVdbK-0LyBSac6eNqVZB1C0QxjE4xeBK_o/edit#gid=0');
var accessToken = e.messageMetadata.accessToken;
var messageId = e.messageMetadata.messageId;
GmailApp.setCurrentMessageAccessToken(accessToken);
var mailMessage = GmailApp.getMessageById(messageId);
var attachmentDetails = [];
var attachments = mailMessage.getAttachments();
for (var k = 0; k < attachments.length; k++) {
attachmentDetails.push(attachments[k].getName());
attachmentDetails.push(attachments[k].getSize());
}
sheet.appendRow([mailMessage.getSubject(), mailMessage.getDate(), mailMessage.getFrom(), attachmentDetails.join('\n')]);
return actionResponse.build();
}
我正在尝试创建一个 Gmail 附加范围 access token,我目前的目标是以某种方式在电子表格中获取所选邮件的附件和内容。
function onGmailDo(e) {
var sheet = SpreadsheetApp.openByUrl(
"https://docs.google.com/spreadsheets/d/14qsqQqHWQyVdbK-0LyBSac6eNqVZB1C0QxjE4xeBK_o/edit#gid=0"
);
var accessToken = e.messageMetadata.accessToken;
var messageId = e.messageMetadata.messageId;
GmailApp.setCurrentMessageAccessToken(accessToken);
var mailMessage = GmailApp.getMessageById(messageId);
var threads = GmailApp.getInboxThreads(0, 100);
var attachmentDetails = [];
var attachments = mailMessage.getAttachments();
for (var k = 0; k < attachments.length; k++) {
attachmentDetails.push(
"${attachments[k].getName()} :${attachments[k].getSize()}"
);
}
sheet.appendRow([
mailMessage.getSubject(),
mailMessage.getDate(),
mailMessage.getFrom(),
attachmentDetails.join("\n"),
]);
}
缺少一些有用的服务。此外,出于授权目的,我还必须在我的清单文件中包含以下范围。 范围:“https://mail.google.com/”、“https://www.googleapis.com/auth/spreadsheets” 更正后的代码:
function onGmailDo(e) {
console.log(e);
var text = e.parameters.text;
var isHomepage = e.parameters.isHomepage === 'true';
var card = createCard(text, isHomepage);
var navigation = CardService.newNavigation()
.updateCard(card);
var actionResponse = CardService.newActionResponseBuilder()
.setNavigation(navigation);
var sheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/14qsqQqHWQyVdbK-0LyBSac6eNqVZB1C0QxjE4xeBK_o/edit#gid=0');
var accessToken = e.messageMetadata.accessToken;
var messageId = e.messageMetadata.messageId;
GmailApp.setCurrentMessageAccessToken(accessToken);
var mailMessage = GmailApp.getMessageById(messageId);
var attachmentDetails = [];
var attachments = mailMessage.getAttachments();
for (var k = 0; k < attachments.length; k++) {
attachmentDetails.push(attachments[k].getName());
attachmentDetails.push(attachments[k].getSize());
}
sheet.appendRow([mailMessage.getSubject(), mailMessage.getDate(), mailMessage.getFrom(), attachmentDetails.join('\n')]);
return actionResponse.build();
}