Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function addMenu() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Datanews API')
.addItem('Get News','myFunction')
.addToUi();
}
function myFunction() {
var API_KEY = "your api key";
var url = "http://api.datanews.io/v1/headlines?q=travel&apiKey=" + API_KEY;
var response = UrlFetchApp.fetch(url);
var data = JSON.parse(response.getContentText());
var results = data.hits;
var sheet = SpreadsheetApp.getActiveSheet();
var header = ["Title", "Description", "URL", "Published Date"]
var items = [header];
results.forEach(function (result) {
items.push([result.title, result.description, result.url, result.pubDate]);
});
sheet.getRange(1,1,items.length,items[0].length).setValues(items);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment