【发布时间】:2016-07-22 14:33:06
【问题描述】:
第一次尝试谷歌应用脚本。我在谷歌电子表格中使用 api 键设置了这个脚本,并将其添加到脚本中的 url 变量中。该脚本运行没有错误,但我不知道如何在单个单元格中显示特定变量。我查看了文档,但还没有遇到类似的示例。
如果我在 A 列中有 ISBN,我会在 B 列中输入什么来显示标题?
function getBookDetails(isbn) {
// Query the book database by ISBN code.
isbn = isbn || "9781451648546"; // Steve Jobs book
var url = "https://www.googleapis.com/books/v1/volumes?key=myAPI&q=isbn:" + isbn;
var response = UrlFetchApp.fetch(url);
var results = JSON.parse(response);
if (results.totalItems) {
// There'll be only 1 book per ISBN
var book = results.items[0];
var title = (book["volumeInfo"]["title"]);
var subtitle = (book["volumeInfo"]["subtitle"]);
var authors = (book["volumeInfo"]["authors"]);
var printType = (book["volumeInfo"]["printType"]);
var pageCount = (book["volumeInfo"]["pageCount"]);
var publisher = (book["volumeInfo"]["publisher"]);
var publishedDate = (book["volumeInfo"]["publishedDate"]);
var webReaderLink = (book["accessInfo"]["webReaderLink"]);
}
}
【问题讨论】:
标签: javascript google-apps-script google-sheets