我无法将歌曲添加到我的Spotify播放列表。

huangapple go评论62阅读模式
英文:

I cant add songs to my playlist at spotify

问题

I try to add a song to my playlist at Spotify. Here is my code:

import requests
import json

user_id = "user_id"
playlist_id = "playlist_id"

url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"
headers = {
    'Authorization': 'Bearer secret_auth_token',
    'Content-Type': 'application/json',
}
payload = {
    "uris": ["spotify:track:64PgpLHuQK3UJ5qZ875Vei"],
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

print(response.text)

Then I got this error:
requests.exceptions.InvalidSchema: No connection adapters were found for "https://api.spotify.com/v1/playlists/2oNkSJU1mGfTAg3ii9nLwc/tracks"

I have tested my auth token. It has necessary scopes. For example, I can create a playlist with this token. But I don't know why I can't add songs to my playlist when I try it with the code above. I am a new learner. If you can simplify the answer, that would help a lot.

英文:

I try to add a song to my playlist at spotify. Here is my code:

import requests
import json

user_id = "user_id"
playlist_id = "playlist_id"

url = f'"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"'
headers = {
    'Authorization': 'Bearer secret_auth_token',
    'Content-Type': 'application/json',
}
payload = {
    "uris": ["spotify:track:64PgpLHuQK3UJ5qZ875Vei"], 
}


response = requests.post(url, headers=headers, data=json.dumps(payload))

print(response.text)

Then I got this error:
requests.exceptions.InvalidSchema: No connection adapters were found for '"https://api.spotify.com/v1/playlists/2oNkSJU1mGfTAg3ii9nLwc/tracks"'

I have tested my auth token. It has necessary scopes. For example I can create playlist with this token. But I dont know why I can't add songs to my playlist when I try it with the code above. I am new learner if u can simplify the answer that would help a lot.

答案1

得分: 1

这是因为您在URL中使用了单引号和双引号的组合。尝试将其替换为以下内容,应该按预期工作:

url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"

英文:

This is due to the combination of single and double quotes you are using in your URL. Try to replace it with this and it should work as expected:

url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"

huangapple
  • 本文由 发表于 2023年5月22日 19:12:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76305574.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定