Ruby China API V3 获取 token 一直失败,HTTP 请求响应码 401,Body 如下,请问该如何解决,谢谢!
{
"error": "invalid_client",
"error_description": "由于未知、不支持或没有客户端,认证失败"
}
使用 curl 获取:
curl -X POST -d "grant_type=password" -d "username=[name]" -d "password=[pass]" 'https://ruby-china.org/oauth/token'
* Adding handle: conn: 0x7fd1b280aa00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fd1b280aa00) send_pipe: 1, recv_pipe: 0
* About to connect() to ruby-china.org port 443 (#0)
* Trying 61.174.15.167...
* Connected to ruby-china.org (61.174.15.167) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
* Server certificate: www.ruby-china.org
* Server certificate: StartCom Class 1 Primary Intermediate Server CA
* Server certificate: StartCom Certification Authority
> POST /oauth/token HTTP/1.1
> User-Agent: curl/7.30.0
> Host: ruby-china.org
> Accept: */*
> Content-Length: 70
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 70 out of 70 bytes
< HTTP/1.1 200 OK
* Server nginx/1.8.0 is not blacklisted
< Server: nginx/1.8.0
< Date: Thu, 04 Jun 2015 05:13:35 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Strict-Transport-Security: max-age=31536000
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Cache-Control: no-store
< Pragma: no-cache
< ETag: W/"5275890161f17844e4dffefe6e643344"
< X-Request-Id: 9d8e536c-3fb6-456e-a3b1-8f88a9799a77
< X-Runtime: 0.296195
<
* Connection #0 to host ruby-china.org left intact
{"access_token":"xxxxxxxx","token_type":"bearer","expires_in":86400,"refresh_token":"xxxxxxxxxx","created_at":1433394815}
#2 楼 @wppurking 为什么我尝试请求,结果如下,能麻烦再测试一下吗?谢谢!
{"error":"invalid_grant","error_description":"登录回调地址无效、过期或者已经被撤销了"}
麻烦查看一下问题在哪里,谢谢了!
#10 楼 @huacnlee #11 楼 @wppurking 谢谢!参考 https://ruby-china.org/topics/14656 ,问题解决了,在发送获取 token 的 POST 请求时,需要加入 HTTP Basic Authentication Header。