I’m currently dealing with an API for video data retrieval, and I’m encountering an error that indicates I’m not subscribed to the service, despite having a valid API key configured. Here’s how I’ve set everything up:
import axios from 'axios';
const BASE_API_URL = 'https://youtube-v31.p.rapidapi.com';
const config = {
params: {
maxResults: '50'
},
headers: {
'X-RapidAPI-Key': process.env.REACT_APP_RAPID_API_KEY,
'X-RapidAPI-Host': 'youtube-v31.p.rapidapi.com'
}
};
export const callAPI = async(url) => {
const response = await axios.get(`${BASE_API_URL}/${url}`, config);
return response.data;
};
And here’s an example of how I’m using it:
import { callAPI } from '../services/apiService';
const VideoFeed = () => {
const [categoryChosen, setCategoryChosen] = useState('Latest');
const [videoItems, setVideoItems] = useState([]);
useEffect(() => {
callAPI(`search?part=snippet&q=${categoryChosen}`)
.then(data => setVideoItems(data.items))
.catch(err => {
if (err.response) {
console.error('Server error:', err.response.data);
} else if (err.request) {
console.error('No response received:', err.request);
} else {
console.error('Request setup error:', err.message);
}
});
}, [categoryChosen]);
Despite having my API key correctly set in the .env file, I keep getting the message ‘You are not subscribed to this API’. What could be wrong, and how can I resolve this?