curl -X "POST" -H "Authorization: Basic e2...Z9" \ -d grant_type=client_credentials https://accounts.spotify.com/api/token
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 92 100 63 100 29 364 167 --:--:-- --:--:-- --:--:-- 531
となります。アクセストークが見つかりません。
curl -v -X "POST" -H "Authorization: Basic e2...Z9" \ -d grant_type=client_credentials https://accounts.spotify.com/api/token
-vすると、
Note: Unnecessary use of -X or --request, POST is already inferred.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 104.199.240.211...
- TCP_NODELAY set
- Connected to accounts.spotify.com (104.199.240.211) port 443 (#0)
- ALPN, offering h2
- ALPN, offering http/1.1
- successfully set certificate verify locations:
- CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
} [5 bytes data]
- (304) (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
- (304) (IN), TLS handshake, Server hello (2):
{ [109 bytes data]
- NPN, negotiated HTTP2 (h2)
{ [5 bytes data]
- TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [2481 bytes data]
- TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
- TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
- TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
- TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data]
- TLSv1.2 (OUT), TLS handshake, Unknown (67):
} [36 bytes data]
- TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
- SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
- ALPN, server did not agree to a protocol
- Server certificate:
- subject: C=SE; L=Stockholm; O=Spotify AB; CN=*.spotify.com
- start date: May 16 00:00:00 2017 GMT
- expire date: Jul 29 12:00:00 2020 GMT
- subjectAltName: host "accounts.spotify.com" matched cert's "*.spotify.com"
- issuer: C=US; O=DigiCert Inc; CN=DigiCert SHA2 Secure Server CA
- SSL certificate verify ok.
- Using HTTP2, server supports multi-use
- Connection state changed (HTTP/2 confirmed)
- Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]
- Using Stream ID: 1 (easy handle 0x55a10a14a580)
} [5 bytes data]
POST /api/token HTTP/2
Host: accounts.spotify.com
User-Agent: curl/7.58.0
Accept: /
Authorization: Basic e2Y2M2ZmMDUzOTQyMTRmY2ZhMWE1MmQ1MDdmODk4ZjUxfTp7MWRlNWI1NmIyYjEyNDdhM2JkNTk2NmM5ZWJlZDNhMDZ9
Content-Length: 29
Content-Type: application/x-www-form-urlencoded
{ [5 bytes data]
- Connection state changed (MAX_CONCURRENT_STREAMS updated)!
} [5 bytes data]
- We are completely uploaded and fine
{ [5 bytes data]
< HTTP/2 400
< server: nginx
< date: Fri, 21 Jun 2019 12:00:01 GMT
< content-type: application/json
< content-length: 63
<
{ [63 bytes data]
100 92 100 63 100 29 351 162 --:--:-- --:--:-- --:--:-- 511
- Connection #0 to host accounts.spotify.com left intact
となり、アクセストークンが帰ってきません。
参考
Spotify Web APIの使い方 | DevelopersIO
https://dev.classmethod.jp/etc/about-using-of-spotify-api/
Client Credentials Flowでアクセストークンを取得
まずは、Client IDとClient SecretをBase64でエンコードした値を取得します。
Macならばターミナル上で下記を実行します。
echo -n {client_id}:{Client_Secret} | base64
出力された値を「ZjM4ZjAw...WY0MzE=」とした場合、以下のようにリクエストを実行します。
curl -X "POST" -H "Authorization: Basic ZjM4ZjAw...WY0MzE=" \ <br />-d grant_type=client_credentials https://accounts.spotify.com/api/token
以下のような結果が返ってくるので、アクセストークンを控えておきます。
{
"access_token": "NgCXRKc...MzYjw",
"token_type": "Bearer",
"expires_in": 3600,
"scope": ""
}
あなたの回答
tips
プレビュー