GIPHY API not returning expected data - getting empty response

I’m having trouble with my GIPHY API integration and can’t figure out what’s going wrong. When I make a request to fetch trending GIFs, I’m not getting the actual GIF data back that I expect. The API call seems to execute but the response doesn’t contain the GIF results I need. I’ve been stuck on this for a while and would really appreciate some help figuring out where I went wrong in my code.

const fetchTrendingGifs = async () => {
  const response = await fetch("https://api.giphy.com/v1/gifs/trending", {
    params: {
      api_key: "your_api_key_here_xxxxxxxxxx"
    }
  });
  console.log(response);
}

useEffect(() => {
  fetchTrendingGifs();
})

The response I get doesn’t show the actual GIF data. What am I missing here? Any help would be great!

make sure ur api key is valid. I’ve had issues with that too, sometimes Giphy returns a 200 with an error in the response. also, check if ur hitting the rate limits, they tightened up on that recently.

Your fetch request is set up wrong. You’re using a params object in the fetch options, but fetch doesn’t work that way. You need to put the parameters directly in the URL as query parameters. Also, you’re logging the response object instead of the actual JSON data. Here’s the fix:

const fetchTrendingGifs = async () => {
  const apiKey = "your_api_key_here_xxxxxxxxxx";
  const response = await fetch(`https://api.giphy.com/v1/gifs/trending?api_key=${apiKey}`);
  const data = await response.json();
  console.log(data);
}

I made this exact mistake when I started using the GIPHY API. The response object just has HTTP request metadata - you need to call .json() on it to get the parsed data with your GIF results.

There’s another issue beyond what Harry mentioned. Your useEffect is running infinitely because you don’t have a dependency array. This means your API is getting hammered with requests.

Add an empty dependency array to make it run only once:

useEffect(() => {
  fetchTrendingGifs();
}, []); // <- This empty array is crucial

I’ve seen this crash staging environments when junior devs forget the dependency array. The API calls just keep firing non-stop.

Also, you might want to add some error handling since the GIPHY API can be flaky:

const fetchTrendingGifs = async () => {
  try {
    const apiKey = "your_api_key_here_xxxxxxxxxx";
    const response = await fetch(`https://api.giphy.com/v1/gifs/trending?api_key=${apiKey}`);
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    const data = await response.json();
    console.log(data.data); // The actual GIFs are in data.data
  } catch (error) {
    console.error('Failed to fetch GIFs:', error);
  }
}

This video breaks down the GIPHY API really well if you want to see the full implementation:

One more thing - make sure your API key is valid and not hitting rate limits. GIPHY’s pretty generous but they do throttle requests.