【发布时间】:2022-11-21 12:44:30
【问题描述】:
我正在尝试使用 google apps 脚本将具有特定主题行的(Gmail)电子邮件的屏幕截图获取到 Google 表格中。我找到了一个source,可以获取网站的截图。这是示例代码:
var siteUrl = "### URL you want to retrieve a screenshot. ###";
var url ="https://www.googleapis.com/pagespeedonline/v4/runPagespeed?screenshot=true&fields=screenshot&url=" +
encodeURIComponent(siteUrl);
var res = UrlFetchApp.fetch(url).getContentText();
var obj = JSON.parse(res);
var blob = Utilities.newBlob(Utilities.base64DecodeWebSafe(obj.screenshot.data),
"image/png",
"sample.png"
);
DriveApp.createFile(blob);
我们可以通过对特定主题行使用以下行来获取线程:
var threads = GmailApp.search('subject:"Daily Report"')
var msgs = GmailApp.getMessagesForThreads(threads);
但由于我的新手技能,我无法将它们拼接起来以获得这封特定主题行电子邮件的屏幕截图。我想知道是否有办法解决这个问题。任何指导将不胜感激。谢谢你。
【问题讨论】:
-
首先,对于我的示例脚本对您的情况没有用,我深表歉意。关于你的放映脚本,我是2021年12月9日更新的,请大家注意。但是,不幸的是,在当前阶段,无法使用“方法:pagespeedapi.runpagespeed”直接检索来自Gmail 的邮件的屏幕截图。因为 Gmail 邮件的 URL 不能公开共享。因此,在这种情况下,需要使用变通方法。但是,我无法想象您对
get the screenshot of the (Gmail) email的预期结果。例如,您需要的屏幕截图只是 HTML 正文? -
感谢您的回复,是的,我只想要我们打开任何电子邮件时看到的界面截图。
-
谢谢你的回复。关于
I just want the screenshot of the interface which we see when we open any email.,我认为在现阶段,这是无法实现的,因为Gmail邮件的URL不能公开分享。我为此道歉。 -
有没有解决办法,因为我们没有公开分享,我们只是使用我们想要截图的个人电子邮件地址授权脚本
-
貌似在使用“pagespeedapi.runpagespeed”的时候要求url是public link。但是,Gmail 的 URL 不是公共链接。这样,当我的示例脚本与 Gmail 消息的 URL 一起使用时,将检索登录屏幕。所以,我问了我的解决方法。但是,从
yes, I just want the screenshot of the interface which we see when we open any email.,我了解到我的解决方法对您的情况没有用。我为此道歉。
标签: parsing google-apps-script google-sheets gmail screenshot