I'm getting 401 error when I'm trying to get data from spotify API in svelte

55 Views Asked by At
<script>
import { onMount } from 'svelte';
  import axios from 'axios';

  export let access_token;
  let displayName = '';
  let errors = [];

  const requestAPI = async () => {
    try {
      const res = await axios.get('https://api.spotify.com/v1/me', {
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${access_token}`
        }
      });
      displayName = res.data.display_name || 'User';
    } catch (err) {
      errors.push(err);
    }
  };

  onMount(() => {
    requestAPI();
  });
</script>

I tried using Got and normal fetch nothing worked. I have done all authorization properly and also access_token wasn't expired.

0

There are 0 best solutions below