Created
December 15, 2015 16:00
-
-
Save anonymous/68e6721a6ee4bbd4c830 to your computer and use it in GitHub Desktop.
Example of doing an image search on getty images and doing something with the first result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var API_KEY_NOT_SECRET = 'insert here'; | |
var xhr = new XMLHttpRequest(); | |
xhr.onload = function () { | |
console.log('response', JSON.parse(xhr.responseText)); | |
var img = document.createElement('img'); | |
img.src = JSON.parse(xhr.responseText).images[0].display_sizes[0].uri; | |
document.getElementsByTagName('body')[0].appendChild(img); | |
}; | |
xhr.onerror = function (e) { console.error(e); }; | |
xhr.open('GET', 'https://api.gettyimages.com/v3/search/images?phrase=milk'); | |
xhr.setRequestHeader('Api-Key', API_KEY_NOT_SECRET); | |
xhr.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment