Error429 was received from a GET request made to the Imgur API

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

Cheers https://i.stack.imgur.com/IiSOW.png

Answer №1

After some tweaking, I updated my start script in package.json to be as follows: "start": "react-scripts start --host 0.0.0.0", following a suggestion referenced by an individual on this thread. With this change, I accessed in my browser and successfully received a response from imgur.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Nestjs: Accessing the request or context using a Decorator

In my current project using NestJS, I am attempting to make the executionContext accessible in a logger for the purpose of filtering logs by request. Each injectable has its own instance of a logger, and I want to maintain this setup (where the scope of t ...

Design a model class containing two arrow functions stored in variables with a default value

I am looking to create a model class with two variables (label and key) that store functions. Each function should take data as an input object. If no specific functions are specified, default functions should be used. The default label function will retur ...

The expanding submenus within each menu are activated by a simple click

I am facing an issue with my menus and submenus. Whenever I click on a menu, all the associated submenus also open up. How can I make it so only the parent submenu opens? https://i.stack.imgur.com/7FDq3.png const [subMenu, setSubMenu] = useState(false) ...

The module named "tapable" does not contain an export for the item "Tapable"

While developing a WordPress plugin for a custom Gutenberg block, I encountered a challenge. I needed to incorporate additional scripts in TypeScript and opted to use "$ tsc --watch" along with a "tsconfig.json" file for compilation. Upon installing @word ...

What makes Mathematics a unique object in JavaScript programming?

Recently, I've dived into learning Javascript, so pardon me if my doubts seem a bit illogical. I came across the definition for a Math object, and here is the code snippet: interface Math { /** The mathematical constant e. This is Euler's nu ...

Dynamic adding of Twitter metatags in Next.js 13: A step-by-step guide

In my project using Next.js 13, I've successfully implemented the generateMetaData function for dynamic metadata with openGraph. However, I am unsure how to do the same for Twitter meta tags. export async function generateMetadata( {params, searchPara ...

Responsive images in Next JS with customized dimensions for optimal viewing experience

I'm currently working on creating an image grid similar to AirBnB using Next JS. To ensure responsiveness, I decided to use Next Image with a responsive layout. However, I ran into an issue where the images are not displaying as square - their height ...

Loop through an array of strings

When I receive the data as a string[] https://i.sstatic.net/ttyag.png However, when I attempt to loop over it subUrl(arr) { for(let i of arr) { console.log(i); } } No output is being logged. What could be causing this issue? ...

Combine all TypeScript enums into a single one

Looking for a way to combine two separate enums into one for easier use. export enum ActionTypes1 { ClearError = 'CLEAR_ERROR', PrependError = 'PREPEND_ERROR', } export enum ActionTypes2 { IncrementCounter = 'INCREMENT_COUNT ...

WebSocket connection outbound from Docker container fails to establish

Running a TypeScript program on Docker that needs to open a Websocket connection to an external server can be a bit tricky. Here is the scenario: ----------------------- ------------------------------ | My Local Docker | ...

Combining Different Types of Errors

Can TypeScript's type system be exploited to provide additional information from a repository to a service in case of errors? I have a service that needs a port for a repository (Interface that the Repository must implement), but since the service mu ...

Tips for adjusting the width of a Facebook embedded video within its container using ReactPlayer

Has anyone encountered issues with adding an embedded video to a NextJS app using ReactPlayer and Facebook videos? It seems that Facebook does not support the width="100%" attribute, as it always snaps back to 500px. Interestingly, this works wel ...

Why is the user and account object not defined in the Next Auth callback function?

I attempted to log session.user.accessToken and clientsecret but they were undefined. I then checked NextAuth.js to investigate the issue, where it appeared that account and user were undefined in the jwt callback function. Despite console.log(account) re ...

Utilizing Generic Types for Object Parameters

Why am I encountering an error when trying to use a function of type A for a B type one? How can I define a function type with unknown properties? When I attempt to define props in type B as props: Record<string, unknown>, it results in a similar err ...

I'm encountering an issue with my array in JavaScript while using // @ts-check in VS Code. Why am I receiving an error stating that property 'find' does not exist on my array? (typescript 2.7

** update console.log(Array.isArray(primaryNumberFemales)); // true and I export it with: export { primaryNumberFemales, }; ** end update I possess an array (which is indeed a type of object) that is structured in the following manner: const primar ...

The base class is invoking a function from its child class

There are two classes, a base class and a derived one, each with an init function. When constructing the derived class, it should: Call its base constructor which: 1.1. Calls its init function Call its own (derived) init function. The issue is that ...

Testing a NestJS service with multiple constructor parameters can be done by utilizing various techniques such as dependency

Content When testing a service that needs one parameter in the constructor, it's essential to initialize the service as a provider using an object instead of directly passing the service through: auth.service.ts (example) @Injectable() export class ...

Customizing the Position of Material UI Select in a Theme Override

I'm trying to customize the position of the dropdown menu for select fields in my theme without having to implement it individually on each select element. Here's what I've attempted: createMuiTheme({ overrides: { MuiSelect: { ...

Is it impossible to use type as a generic in TypeScript?

Struggling with TypeScript in React and encountered an issue. I decided to use a generic to build an abstracted class related to Axios. However, I ran into an ESLint error when using any as the type parameter for my generic. ESLint: Unexpected any. Specif ...

Guide on how to "attach" the routes of an Angular 2 module to a specific location within the routing structure

Let's consider a scenario where the main routing module is defined as follows: // app-routing.module.ts const appRoutes: Routes = [ { path: 'login', component: LoginComponent }, { path: 'auth', ...