Spotify API unsupported_grant_type

问题描述 投票:0回答:1

我正在使用client credentials flow对Spotify API进行身份验证。我有我应该设置的所有内容,但每当我发送rquest时仍然会收到以下错误。

400 Bad Request: {"error":"unsupported_grant_type","error_description":"grant_type must be client_credentials, authorization_code or refresh_token"}

相关代码如下:

sub get_spotify_token{
    my $data={grant_type => "client_credentials"};

    my $req=HTTP::Request->new("POST",AUTH_TOKEN_URL,[
        "Content-Type" => "application/x-www-form-urlencoded",
        "Authorization" => "Basic $ENV{SPOTIFY_CLIENT_B64}",
    ],encode_utf8 encode_json $data);

    # send request
    my $res=$ua->request($req);

    # return token or die on error
    if($res->is_success){
        return %{decode_json $res->content}{"access_token"};
    }else{
        die $res->status_line.": ".$res->content."\n";
    }
}
perl http oauth spotify
1个回答
3
投票

API要求你提供的qazxsw poi(qazxsw poi),但是你提供的是JSON(application/x-www-form-urlencoded)。

grant_type=client_credentials{"grant_type":"client_credentials"}可以很容易地建立一个HTTP::Request::Common响应。

POST

要么

application/x-www-form-urlencoded
© www.soinside.com 2019 - 2024. All rights reserved.