Last active
August 1, 2021 19:26
-
-
Save koraytugay/96c8f5b5e5e9c53f6625df2c1365a60d to your computer and use it in GitHub Desktop.
Flickr - Fetch Photos
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-inline' *.flickr.com *.staticflickr.com"> | |
<title>Page Title</title> | |
<style> | |
.photoContainer { | |
margin: 10px | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container" style="padding: 20px"> | |
<div id="loading">Loading..</div> | |
</div> | |
<script> | |
const flickrHost = 'https://api.flickr.com/services/rest/' | |
const method = 'flickr.people.getPublicPhotos'; | |
const userId = '32951986%40N05'; | |
const extras = 'url_q'; | |
const format = 'json' | |
const apiKey = '96821c7dfcaab077324ce1a270c5a6f6'; | |
const noJsonCallback = "1" | |
const flickrRest = `${flickrHost}?method=${method}&user_id=${userId}&extras=${extras}&format=${format}&nojsoncallback=${noJsonCallback}&api_key=${apiKey}`; | |
window.onload = () => { | |
searchFlickr().then(photoList => { | |
document.getElementById("loading").hidden = true | |
for (let photo of photoList) { | |
const photoContainer = document.createElement("span"); | |
photoContainer.classList.add("photoContainer") | |
let image = document.createElement("img"); | |
image.src = photo["url_q"]; | |
image.title = photo["title"]; | |
photoContainer.appendChild(image); | |
document.getElementById("container").appendChild(photoContainer); | |
} | |
}); | |
} | |
async function searchFlickr() { | |
let response = await fetch(flickrRest); | |
let data = await response.json(); | |
let {photos: {photo: photoList}} = data; | |
return photoList; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment