【问题标题】:Spotify Oauth, Getting users profileSpotify Oauth,获取用户资料
【发布时间】:2016-08-07 22:16:27
【问题描述】:

我正在尝试允许用户使用他们的 spotify 帐户登录我的网站,但会收到

{"error":"server_error","error_description":"意外状态:415"}

收到 JSON 响应时。

这是我正在使用的代码:

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;

我在 spotify 文档中排在第 4 位...https://developer.spotify.com/web-api/authorization-guide/

谢谢

【问题讨论】:

    标签: php json curl oauth spotify


    【解决方案1】:

    错误很可能是由于表单数据被发布为multipart/form-data(因为您将数组传递给CURLOPT_POSTFIELDS)。

    请尝试:

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

    这样它将数据作为application/x-www-form-urlencoded 发布。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 2015-05-12
      相关资源
      最近更新 更多