I am trying to do a Axios request but when I do. I get the error "[AxiosError: Request failed with status code 403]" This is strange as when I put that token and api_url into a online REST Get request it works and returns output. This was pulled from my friends Git and for him it works and returns a response and not a error. So I am wondering why Axios isn't working for me.
import { View, Text, Button } from "react-native";
import React, { useState, useEffect } from "react";
import axios from "axios";
import { getSpotifyToken } from "../../hooks/spotifyAuth";
import { setSpotifyToken } from "../../hooks/spotifyAuth";
const getTopArtists = async () => {
//Getting spotify token
const spotifyToken = getSpotifyToken();
console.log("Getting access Token for TopSongs:", spotifyToken);
const api_url =
"https://api.spotify.com/v1/me/top/artists?time_range=medium_term&limit=5";
try {
const response = await axios.get(api_url, {
headers: {
Authorization: `Bearer ${spotifyToken}`,
},
});
console.log(response.data);
return response.data.items;
} catch (error) {
setSpotifyToken("");
console.log(error);
}
};