错误 ‘invalid_client’ 在使用 JavaScript、Ionic 6 和 Angular 与 Spotify API 时发生。

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

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 '.

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

发表评论

匿名网友

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

确定