Encountering a
Request failed with status code 429
error from the Imgur API
despite using a new Client_ID
that hasn't been used before,
Here is my Api.ts:
const imgurClientId = process.env.NEXT_PUBLIC_Client_ID
const BASE = "https://api.imgur.com/3";
const EP_GALLERY = `${BASE}/gallery`;
const EP_GALLERY_TAGS = `${BASE}/tags`;
async function imgurBaseApi(args: Args) {
const myHeaders = new Headers({
Authorization: `Client-ID ${imgurClientId}`,
});
args.requestOptions = {
...args.requestOptions,
headers: myHeaders,
method: "GET",
};
const response = await fetch(args.endPoint, args.requestOptions);
const responseJson = await response.json();
return responseJson.data;
}
// how I use it:
async function getGalleryTagMetadata(requestArgs: TypeState["requestArgs"]) {
const endPoint = `${EP_GALLERY}/t/${requestArgs.tagName}/${requestArgs.sort}/${requestArgs.window}/${requestArgs.page}`;
return imgurBaseApi({ endPoint: endPoint });
}
Attempted a simple fetch
call as well:
const imgurClientId = process.env.NEXT_PUBLIC_Client_ID
const sort = 'viral'
const window = 'day'
const page = 1
const url = `https://api.imgur.com/3/gallery/search/${sort}/${window}/${page}?q=cats`
const requestOptions = {
method: 'GET',
headers: new Headers({
Authorization: `Client-ID ${imgurClientId}`,
}),
}
fetch(url, requestOptions)
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`)
}
return response.json()
})
.then((data) => {
console.log('dta', data)
})
.catch((error) => {
console.error('Error:', error)
})
Followed the Imgur documentation for setting up the Client_ID
, successful with Postman making a GET
request.
Query:
For an image-only application, is 0auth2 necessary?
ps. Full code available upon request.
Thank you in advance