Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的Spotify API验证-重定向URI无效_Php_Spotify - Fatal编程技术网

PHP中的Spotify API验证-重定向URI无效

PHP中的Spotify API验证-重定向URI无效,php,spotify,Php,Spotify,我正在尝试连接到Spotify API 我通过以下方式获得授权代码: <?php $redirect_uri = 'http%3A%2F%2Flocalhost%3A8000'; ?> <a href="https://accounts.spotify.com/authorize?client_id=<?php echo $client_id;?>&response_type=code&redirect_uri=<?php echo $redi

我正在尝试连接到Spotify API

我通过以下方式获得授权代码:

<?php
$redirect_uri = 'http%3A%2F%2Flocalhost%3A8000';
?>
<a href="https://accounts.spotify.com/authorize?client_id=<?php echo $client_id;?>&response_type=code&redirect_uri=<?php echo $redirect_uri; ?>&scope=user-read-private%20user-read-email&state=34fFs29kd09">Get code</a><br/><br/>
我已经在Spotify仪表板中列出了我能想象到的所有变化:

但我得到了这个错误:

result: {"error":"invalid_grant","error_description":"Invalid redirect URI"}
编辑:奇怪的是,我可以使用重定向URI http:%2F%2Flocalhost%3A8000成功链接到隐式授权客户端方法-因此我知道这是正确的白名单。我在上面发布的代码中使用了这个URI,得到了相同的错误。我还使用了我能想到的所有其他组合,无论是使用:%2F%2F、%3A%2F%2F、尾随斜杠、尾随%3A等等。每次都会出现相同的错误

有什么想法吗

edit2:如果我使用$redirect_uri=;我得到一个不同的错误:

result: {"error":"invalid_request","error_description":""}

现在您已经停止对重定向uri进行编码,它正在抱怨参数无效

根据文档,client_id和secret不应与其他参数一起发送,它们需要通过授权标头添加到标头中:


你有没有在没有端口的情况下尝试过它?是的,如果代码中有非法的重定向uri,只是将其添加到白名单中,没有任何效果。发现了一个可能重复的问题我想$redirect\u uri应该是未编码的形式,即$redirect\u uri=http://localhost:8000'; http_build_查询应该为您编码。实际上,URI不应该在usageBingo中编码,谢谢!你的建议确实解决了这个问题-但是对于未来的读者,我将添加以下内容-你实际上可以发送客户端id和密码以及其他参数,文档声明:发送客户端id和密码的另一种方法是在帖子正文中作为请求参数client_id和client_secret,而不是发送标头中编码的base64。我的错误是我把它作为秘密发送,而不是在邮件正文中作为客户的秘密发送。啊!
result: {"error":"invalid_request","error_description":""}
HEADER PARAMETER Authorization Base 64 encoded string that contains the client ID and client secret key. The field must have the format: Authorization: Basic <base64 encoded client_id:client_secret>