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

Troubleshooting Issue: Relative Paths Fail to Work with routerLink in Angular 6

I seem to be encountering a problem with the Angular app I'm currently developing. It appears that when using relative paths with routerLink throughout the application, it fails to work properly. There are no errors thrown and the navigation does not ...

Implementing useSWRInfinite with a GraphQL query that includes variables and utilizes a cursor - a comprehensive guide

Currently, I have implemented a useSWR hook to fetch the initial 10 links based on a cursor. The code snippet for this is as follows: const AllLinksQuery = gql` query allLinksQuery($first: Int, $after: String) { links(first: $first, after: $after) { ...

Retrieve the client's IP address in NextJS utilizing server-side rendering (SSR)

I am currently working on a weather application and I am retrieving the client IP using IPIFY. However, this method results in losing SSR (Server-Side Rendering), or I can use SSR and get the server IP instead. A suggestion was made to me that I could util ...

Tips on adjusting box-sizing in Chakra UI

Is there a way to customize the global style in Chakra UI to change all elements' box-sizing to border-box? I tried the following code, but it doesn't seem to work. import { extendTheme } from '@chakra-ui/react'; const overrides: obje ...

Combining numerous interfaces into a unified interface in Typescript

I'm struggling to comprehend interfaces in Typescript, as I am facing difficulty in getting them to function according to my requirements. interface RequestData { [key: string]: number | string | File; } function makeRequest(data: RequestData) { ...

Error encountered during Next.js project build: Entry point specified for implicit type library 'build'

While working on my nextjs project, I encountered the following error: Type error: Cannot find type definition file for 'build'. The file is in the program because: Entry point for implicit type library 'build' Can someone guide ...

Setting up the starting value using the useAnimate hook in framer motion

One of the initial properties of the motion component is: <motion.div initial={{ x: "100%" }} animate={{ x: "calc(100vw - 50%)" }} /> When using useAnimate with the useInView hook: const [scope, animate] = useAnimate(); const ...

Having trouble with scrolling in React, Next.js, and Tailwind CSS

I'm encountering an issue with React Next.js where I can't seem to get the vertical scrollbar to appear. Here's the code snippet in question: <div className=" hover:bg-violet-400 box-content overflow-y-scroll w-4000"> ...

What causes the object type to shift away from 'subscribe'?

Currently, I am facing an issue with retrieving a Coupon object from the server using a REST API in combination with Angular. The problem arises when I attempt to access the 'subscribe' method - within the 'subscribe', the object is of ...

The parseFloat function only considers numbers before the decimal point and disregards

I need my function to properly format a number or string into a decimal number with X amount of digits after the decimal point. The issue I'm facing is that when I pass 3.0004 to my function, it returns 3. After reviewing the documentation, I realized ...

Function input custom operator in RxJs

I am currently working on developing a custom rxjs operator. My previous custom operators, such as MonoTypeOperatorFunction or the regular Observable that accepts input like strings or numbers, have been successful. However, I am facing a challenge with cr ...

Adding 30 Days to a Date in Typescript

Discovering Typescript for the first time, I'm attempting to calculate a date that is (X) months or days from now and format it as newDate below... When trying to add one month: const dateObj = new Date(); const month = dateObj.getUTCMonth() + 2; con ...

Pdfjs-dist is incompatible with the upcoming version 14 of the application's router, which is written in JavaScript rather than TypeScript

I am encountering issues with extracting text from PDF files within a browser environment using the input element. The errors I am facing do not appear to be directly related to my code, but rather to the libraries themselves. This problem has persisted a ...

Create a line break in the React Mui DataGrid to ensure that when the text inside a row reaches its maximum

I'm facing an issue with a table created using MUI DataGrid. When user input is too long, the text gets truncated with "..." at the end. My goal is to have the text break into multiple lines within the column, similar to this example: I want the text ...

What could be causing the lack of Tailwind CSS intellisense in a Next.js app with TypeScript?

Check out my tailwind.config.ts file I've been trying to figure it out by watching YouTube tutorials, but nothing seems to be working. Even with the tailwind.config.ts file in my Next.js app, it still isn't functioning properly. Perhaps there&ap ...

Error: Type Error when using custom App and getInitialProps in Next.js

I have a simple app built using the Next JS starter kit, and I am attempting to integrate custom functionality as outlined in the documentation: class MyApp extends App { static async getInitialProps({ Component, router, ctx }) { let pageProps = {}; ...

The process of seamlessly transferring cookies between the client and server using NextJS server actions

Currently, I am exploring the capabilities of NextJS 14 to see how it could enhance the user experience for our clients. Our existing single-page application (SPA) is quite large and slow to load, with much of it going unused during a typical visit by a cl ...

Convert TypeScript-specific statements into standard JavaScript code

For my nextjs frontend, I want to integrate authentication using a keycloak server. I came across this helpful example on how to implement it. The only issue is that the example is in typescript and I need to adapt it for my javascript application. Being u ...

Avoid getting stuck in an infinite loop with useEffect when modifying the query string in Next.js

My challenge involves using a tag input to generate an array of tags. I am looking to incorporate these tags as query string parameters in NextJs using the useRouter function. It is crucial for me to retain the existing query string parameters, as other fi ...

"The Challenge of Inserting a User with BSON-ObjectID into a MongoDB Collection and the Type Error

Whenever I try to add a user object into a MongoDB collection using the insertOne method, I encounter a type error. The issue appears to be related to the compatibility of the _id property in my User object with the expected type in the MongoDB driver. In ...