Skip to content

Instantly share code, notes, and snippets.

@sagunsh
Created July 23, 2020 11:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagunsh/f882d63a4fe800f5d9b090391239069f to your computer and use it in GitHub Desktop.
Save sagunsh/f882d63a4fe800f5d9b090391239069f to your computer and use it in GitHub Desktop.
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