Discover how to integrate v0 with the Getty Images API. This guide covers setup, authentication, and best practices for seamless media integration.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
gettyConfig.ts
in your project’s root directory.export const GETTYAPIKEY = 'YOURGETTYAPIKEYHERE';
gettyImagesAPI.ts
in your project’s root directory.gettyImagesAPI.ts
:import { GETTYAPIKEY } from './gettyConfig';
interface GettyResponse {
result_count: number;
images: Array<{
id: number;
title: string;
display_sizes: Array<{uri: string}>;
}>;
}
export async function searchGettyImages(phrase: string): Promise {
const endpoint = https://api.gettyimages.com/v3/search/images?phrase=${encodeURIComponent(phrase)};
const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Api-Key': GETTYAPIKEY,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(Getty Images API Error: ${response.statusText});
}
return response.json();
}
// Example function to retrieve and log images for a given search phrase.
export async function logImageResults(phrase: string): Promise {
try {
const data = await searchGettyImages(phrase);
console.log("Total Results:", data.result_count);
data.images.forEach(image => {
console.log("Image Title:", image.title);
if (image.displaysizes && image.displaysizes.length > 0) {
console.log("Image URL:", image.display_sizes[0].uri);
}
});
} catch (error) {
console.error("Error fetching Getty Images:", error);
}
}
app.ts
or similar), import the functions from gettyImagesAPI.ts
.logImageResults
function where desired. Here is an example insertion:import { logImageResults } from './gettyImagesAPI';
// Example usage: Searching for "nature" images
async function init() {
await logImageResults("nature");
}
init();
fetch
) and avoid external libraries that require installation.fetch
(though modern browsers already support it), add the following snippet in your HTML file's <head>
section:<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/3.6.2/fetch.min.js"></script>
logImageResults
function.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.