soundcloud/oauth2/token 只返回 401 响应

标签 soundcloud

我注意到我使用 SoundcloudPHP 编写的一些代码今天停止了身份验证,尽管几天前我上次使用它时它运行良好。为了解决这个问题,我一直在尝试使用/oauth2/token 端点进行身份验证,但响应是 401 和空正文。我一直在使用 https://developers.soundcloud.com/docs/api/reference#token 页面上的 curl

从命令行:

curl -v -X POST "https://api.soundcloud.com/oauth2/token" -F 'client_id=MY_ID' -F 'client_secret=MY_SECRET' -F 'grant_type=authorization_code' -F 'redirect_uri=MY_REDIRECT' -F 'code=0000000EYAA1CRGodSoKJ9WsdhqVQr3g'

响应:
* About to connect() to api.soundcloud.com port 443 (#0)
*   Trying 72.21.91.127... connected
* Connected to api.soundcloud.com (72.21.91.127) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES256-SHA
* Server certificate:
*    subject: OU=Domain Control Validated; CN=*.soundcloud.com
*    start date: 2014-04-22 16:52:12 GMT
*    expire date: 2016-04-08 10:08:48 GMT
*    subjectAltName: api.soundcloud.com matched
*    issuer: C=BE; O=GlobalSign nv-sa; CN=GlobalSign Domain Validation CA - SHA256 - G2
*    SSL certificate verify ok.
> POST /oauth2/token HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: api.soundcloud.com
> Accept: */*
> Content-Length: 658
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------e695cc6c8133
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 401 Unauthorized
< Access-Control-Allow-Headers: Accept, Authorization, Content-Type, Origin
< Access-Control-Allow-Methods: GET, PUT, POST, DELETE
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: Date
< Cache-Control: private, max-age=0, must-revalidate
< Date: Thu, 01 Oct 2015 23:25:25 GMT
< Server: am/2
< Content-Length: 0
< 
* Connection #0 to host api.soundcloud.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):

我创建了新的客户端标签,看看它们是否有效,我得到了同样的结果。由于我使用的是文档中提供的 curl,我希望它能够工作。有任何想法吗?

最佳答案

我是 php https://github.com/njasm/soundcloud 的创建者图书馆。

并且它的用户报告了同样的问题,实际上您所说的也是正确的,现在 soundcloud 上的 curl 示例不再起作用(出于某种奇怪的原因)。
调查问题以修复库我发现似乎是内容类型问题。

似乎在请求/刷新 token 时您需要使用的内容类型必须始终是 application/x-form-urlencoded,并且在我们(库)通过与 application/json 的内容类型通信之前正常工作。

如果你是我图书馆的用户,你应该更新到最新的主人。
如果您可以帮助测试修复程序,请返回问题页面 https://github.com/njasm/soundcloud/issues/25

更新:
已确认内容类型必须是 application/x-form-urlencoded

我正在进行一些测试以确认情况确实如此。
如果是这样,我会将提交标记为稳定版本。

祝你好运,希望这能帮到你!

关于soundcloud/oauth2/token 只返回 401 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32898394/

相关文章:

android - Android下Phonegap中的SoundCloud Stream

javascript - 如何循环 Soundcloud 解析 api 而不每秒调用太多次?

php - SoundCloud Api - 无法获取特定用户的所有收藏夹

javascript - Soundcloud 流媒体音频

javascript - 在 Soundcloud 中通过 streamable = true 过滤轨道

android - 使用代码停止诸如Soundcloud和Saavn之类的背景音乐播放器服务

javascript - SoundCloud API : setVolume on audiomanager. js

javascript - Chrome 不会加载 jquery 或 soundcloud api

node.js - 是否可以编写一个CLI来播放Soundcloud的音乐而无需在浏览器中直观地打开Soundcloud?

javascript - 如何使用 Sound Cloud API 按标题搜索轨道?