Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Finding BPMs of songs

Finding BPMs of songs

Plan

Free/Premium

Country

US

 

My Question or Issue

I am trying to make a project that will get the BPMs of a list of songs, and then output them to the user, as well as including some sorting functionality. I am trying to use Spotify to get the BPM of the songs, and then handle the rest myself. My app was briefly working, and since then I have been getting 403 Forbidden errors on all of my requests (except for getting an access token). I am using C# as I am working inside of Unity, and my code for requesting the song BPM looks like this:

public IEnumerator FetchBPMForSong(string trackId, Action<float> onBPMReceived)
{
if (string.IsNullOrEmpty(accessToken))
{
yield return GetAccessToken();
}

string featuresUrl = $"https://api.spotify.com/v1/audio-features/{trackId}";
UnityWebRequest request = UnityWebRequest.Get(featuresUrl);
request.SetRequestHeader("Authorization", "Bearer " + accessToken);

yield return request.SendWebRequest();

if (request.result == UnityWebRequest.Result.Success)
{
var json = JObject.Parse(request.downloadHandler.text);
float bpm = json["tempo"]?.ToObject<float>() ?? 0f;
Debug.Log($"BPM for Track {trackId}: {bpm}");
onBPMReceived?.Invoke(bpm);
}
else
{
Debug.LogError($"Error fetching BPM: {request.error}\nResponse: {request.downloadHandler.text}");
}
}

and my code for getting an access token looks like this:

private IEnumerator GetAccessToken()
{
string authUrl = "https://accounts.spotify.com/api/token";
string credentials = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes($"{ClientId}:{ClientSecret}"));

WWWForm form = new WWWForm();
form.AddField("grant_type", "client_credentials");

UnityWebRequest request = UnityWebRequest.Post(authUrl, form);
request.SetRequestHeader("Authorization", "Basic " + credentials);

yield return request.SendWebRequest();

if (request.result == UnityWebRequest.Result.Success)
{
var json = JObject.Parse(request.downloadHandler.text);
accessToken = json["access_token"]?.ToString();
Debug.Log($"Access Token Retrieved: {accessToken}");
}
else
{
Debug.LogError($"Error fetching access token: {request.error}\nResponse: {request.downloadHandler.text}");
}
}


I'm unsure what causes the issue to start appearing and would appreciate any feedback.

Reply
4 Replies

The Get Track's Audio Features endpoint is deprecated for new apps that had no (pending) quota extension before November 27th.

You can read more about it here. Also, you can leave a reaction at this (pinned) post.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Spotify revoked access for non-production apps to this and several other API endpoints without notice. They left hundreds of developers, you included, out to dry. Sorry. 

So there's just no way around this then? Sounds like really unlucky timing for me then. If I want to continue my project I will need to find a different API to use thats not Spotify? 

As of now yes, unless they decide to reverse course on the policy or reintroduce the API endpoints with different rules. There was a cutoff date for an extension application that may have been mentioned, but that was weeks ago when they closed it. 

Suggested posts