'Spotify API get track_uri or track_id from own spotify data
[enter image description here][1]I have a dataframe that included my own data I've requested from Spotify (https://www.spotify.com/de/account/privacy/) Now, I have .json data, that I've converted to .csv, that is my StreamingHistory ( incl msplayed, timestamp, artist, trackName). I'd like to add the track_id or uri to the dataframe. Is that possible to a match of the trackName and artistName with the Spotify API? Because the API is kind of complex for me now.
Now I'd like to add a new column with the uri/track_id to then get the audio features of the song. As I've said already I don't know if it's possible to get the uri in this way. [1]: https://i.stack.imgur.com/S2UGh.png
CLIENT_ID = ''
CLIENT_SECRET = ''
client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
AUTH_URL ="https://accounts.spotify.com/api/token"
auth_response = requests.post(AUTH_URL, {
'grant_type': 'client_credentials',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
})
#Convert response to JSON
auth_response_data = auth_response.json()
#Save the access token
access_token = auth_response_data['access_token']
#Need to pass access token into header to send properly formed GET request to API server
headers = {
'Authorization': 'Bearer {token}'.format(token=access_token)
}
sp=spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id="CLIENT_ID",client_secret="CLIENT_SECRET"))
BASE_URL = 'https://api.spotify.com/v1/'
df.to_csv(StreamingHistoryEditedComplete.csv)
new_df['songArtistID'] = new_df['artistName'] + ":" + new_df['trackName']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
