英文:
Error 'invalid_client' when using JavaScript and Spotify API with Ionic 6 and Angular
问题
I'm encountering an issue while using JavaScript and the Spotify API in my Ionic 6 with Angular project. Here's the code snippet I'm using:
async function getToken() {
const clientid = 'xxxxx';
const clientsecret = 'xxxxx';
const buf = new Buffer.from(`${clientid}:${clientsecret}`);
const result = await fetch('https://accounts.spotify.com/api/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic' + buf.toString('base64')
},
body: 'grant_type=client_credentials'
});
const data = await result.json();
return data;
}
However, I'm getting the following error: "invalid_client". Can anyone provide some guidance on how to resolve this issue?
Thank you in advance for your help!
英文:
I'm encountering an issue while using JavaScript and the Spotify API in my Ionic 6 with Angular project. Here's the code snippet I'm using:
async function getToken() {
const clientid = 'xxxxx';
const clientsecret = 'xxxxx';
const buf = new Buffer.from(`${clientid}:${clientsecret}`);
const result = await fetch('https://accounts.spotify.com/api/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic' + buf.toString('base64')
},
body: 'grant_type=client_credentials'
});
const data = await result.json();
return data;
}
However, I'm getting the following error: "invalid_client"
. Can anyone provide some guidance on how to resolve this issue?
Thank you in advance for your help!
答案1
得分: 0
The problem was that the 'Basic' was missing a space, so its 'Basic '.
英文:
EDIT: The problem was that the 'Basic' was missing a space, so its 'Basic '.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论