doulipi3742 2016-04-15 19:44
浏览 44
已采纳

Spotify Oauth,获取用户个人资料

I'm trying to allow users to login to my site using their spotify account but receive

{"error":"server_error","error_description":"Unexpected status: 415"}

when receiving the JSON response.

This is the code I'm using:

if (isset($_GET['code'])  ) {
    echo $_GET['code'];
    $scode = $_GET['code'];
    $surl2 = "https://accounts.spotify.com/api/token";
    $sdata2=array("grant_type"=>"authorization_code","code"=>$scode,"redirect_uri"=>$sredicturl,"client_id"=>$Sclient,"client_secret"=>$Ssecret);
    $sch2=curl_init($surl2);
    curl_setopt($sch2,CURLOPT_POST,true);
    curl_setopt($sch2,CURLOPT_POSTFIELDS,$sdata2);
    curl_setopt($sch2,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($sch2,CURLOPT_RETURNTRANSFER,1);
    $sjson_response2=curl_exec($sch2);
    curl_close($sch2);
    echo"<br/>".$sjson_response2;

I'm at number 4 in the spotify documentation... https://developer.spotify.com/web-api/authorization-guide/

Thanks

  • 写回答

1条回答 默认 最新

  • drcomwc134525 2016-04-15 23:00
    关注

    Most likely the error is due to the form data being posted as multipart/form-data (because you are passing an array to CURLOPT_POSTFIELDS).

    Instead, try:

    curl_setopt($sch2,CURLOPT_POSTFIELDS, http_build_query($sdata2));
    

    This way it POSTs data as application/x-www-form-urlencoded.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作