Skip to content

Instantly share code, notes, and snippets.

@gargomoma
Created October 2, 2018 07:39
Show Gist options
  • Save gargomoma/ed70f2860f24ec25e358f0da7be3dcb8 to your computer and use it in GitHub Desktop.
Save gargomoma/ed70f2860f24ec25e358f0da7be3dcb8 to your computer and use it in GitHub Desktop.
Google Apps Script to get random Gif from Giphy
/*
HOW IT WORKS??
https://jeffreyeverhart.com/2016/02/24/using-google-sheet-and-google-apps-script-to-work-with-apis/
https://codepen.io/ChynoDeluxe/pen/WGQzWW
*/
function getGIF() {
// Giphy API defaults
const giphy = {
baseURL: "https://api.giphy.com/v1/gifs/",
key: "APIKEYHERE",
tag: "fail",
type: "random",
rating: "pg-13"
};
// Giphy API URL
var giphyURL = giphy.baseURL +giphy.type+"?api_key="+giphy.key+"&tag="+giphy.tag+"&rating="+giphy.rating;
var response = UrlFetchApp.fetch(giphyURL);
var jsonresponse = response.getContentText();
var jsondata = JSON.parse(jsonresponse);
var gifURL = jsondata.data.images.original.url;
Logger.log(gifURL);
return gifURL
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment