A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.spotify.com/documentation/web-api/tutorials/getting-started below:

Getting started with Web API

Getting started with Web API

This tutorial will help you to make your first Web API call by retriving an artist's metadata. The steps to do so are the following:

  1. Create an app, if you haven't done so.
  2. Request an access token.
  3. Use the access token to request the artist data.

Here we go, let's rock & roll!

Prerequisites

Set Up Your Account

Login to the Spotify Developer Dashboard. If necessary, read the latest Developer Terms of Service to complete your account set up.

Create an app

An app provides the Client ID and Client Secret needed to request an access token by implementing any of the authorization flows.

To create an app, go to your Dashboard, click on the Create an app button and enter the following information:

Finally, check the Developer Terms of Service checkbox and tap on the Create button.

Request an access token

The access token is a string which contains the credentials and permissions that can be used to access a given resource (e.g artists, albums or tracks) or user's data (e.g your profile or your playlists).

In order to request the access token you need to get your Client_ID and Client Secret:

  1. Go to the Dashboard
  2. Click on the name of the app you have just created (My App)
  3. Click on the Settings button

The Client ID can be found here. The Client Secret can be found behind the View client secret link.

With our credentials in hand, we are ready to request an access token. This tutorial uses the Client Credentials, so we must:


_10

curl -X POST "https://accounts.spotify.com/api/token" \

_10

-H "Content-Type: application/x-www-form-urlencoded" \

_10

-d "grant_type=client_credentials&client_id=your-client-id&client_secret=your-client-secret"


The response will return an access token valid for 1 hour:


_10

"access_token": "BQDBKJ5eo5jxbtpWjVOj7ryS84khybFpP_lTqzV7uV-T_m0cTfwvdn5BnBSKPxKgEb11",

_10

"token_type": "Bearer",


Request artist data

For this example, we will use the Get Artist endpoint to request information about an artist. According to the API Reference, the endpoint needs the Spotify ID of the artist.

An easy way to get the Spotify ID of an artist is using the Spotify Desktop App:

  1. Search the artist
  2. Click on the three dots icon from the artist profile
  3. Select Share > Copy link to artist. The Spotify ID is the value that comes right after the open.spotify.com/artist URI.

Our API call must include the access token we have just generated using the Authorization header as follows:


_10

curl "https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb" \

_10

-H "Authorization: Bearer BQDBKJ5eo5jxbtpWjVOj7ryS84khybFpP_lTqzV7uV-T_m0cTfwvdn5BnBSKPxKgEb11"


If everything goes well, the API will return the following JSON response:


_40

"spotify": "https://open.spotify.com/artist/4Z8W4fKeB5YxbusRsdQVPb"

_40

"href": "https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb",

_40

"id": "4Z8W4fKeB5YxbusRsdQVPb",

_40

"url": "https://i.scdn.co/image/ab6761610000e5eba03696716c9ee605006047fd",

_40

"url": "https://i.scdn.co/image/ab67616100005174a03696716c9ee605006047fd",

_40

"url": "https://i.scdn.co/image/ab6761610000f178a03696716c9ee605006047fd",

_40

"uri": "spotify:artist:4Z8W4fKeB5YxbusRsdQVPb"


Congratulations! You made your first API call to the Spotify Web API.

Summary

What's next?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4