How do I get a list of Episodes from a podcast using the Itunes API?

854 views Asked by At

Im building a podcast player project, where you can find a list of podcasts, filter them by a search bar, and so on.

Im supposed to be able to navigate to a podcast and once there, to show all Episodes of that particular Podcast in my WebApp.

I've seen people mention in the Apple Developer Forums, that you could access these episodes with a URL such as this: "https://itunes.apple.com/lookup?id=1251196416&country=US&media=podcast&entity=podcastEpisode&limit=100", however when you navigate to this URL, it opens up a ".txt" file that contains the information, and I don't know how I can use this information on my React Application. It's an app Build with React, @reduxjs/toolkit and Typescript.

My podcastApi looks like this:

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { ITUNES_URL } from '../constants';

export const podcastApi = createApi({
  reducerPath: 'podcastApi',
  baseQuery: fetchBaseQuery({
    baseUrl: `https://api.allorigins.win/get?url=${encodeURIComponent(ITUNES_URL)}`,
  }),
  endpoints: (builder) => ({
    getPodcasts: builder.query({
      query: () => ({
        url: "/us/rss/toppodcasts/limit=100/genre=1310/json",
      }),
    }),
    getPodcastById: builder.query({
      query: (id) => `/lookup?id=${id}`,
    }),
    getEpisodeById: builder.query({
      query: ({ podcastId, episodeId }) => `/podcast/${podcastId}/episode/${episodeId}`,
    }),
   getPodcastEpisodes: builder.query({
    query: (id) => ({ url: `/lookup?id=${id}&country=US&media=podcast&entity=podcastEpisode&limit=100`,
    }),
  }),
  }),
});

So far I've had no success doing this. Any advice please?

I've tried modifying my podcastApi mentioned above in many different ways but it hasn't worked.

1

There are 1 answers

0
Marcia Moss On

this got me the data:

            url: "https://itunes.apple.com/lookup?id=1251196416&country=US&media=podcast&entity=podcastEpisode",
            method: "GET",
          };```

I just took out `&limit=100`, not sure the reason why limit is not working. It was the same issue for song search