2017-08-08 10 views
0

curlを使用してSpotify APIにアクセスしようとしています。私はターミナルから1つのライナーでこれを行うことができ、それは正常に動作します。例:Spotify APIにアクセスするためのBashスクリプト - カールエラー

curl -X GET "https://api.spotify.com/v1/tracks/2vEQ9zBiwbAVXzS2SOxodY" -H "Authorization: Bearer <mytoken>" 

ただし、これをbashスクリプトに埋め込むと、出力されません。ここに私のbashスクリプトがあります:

#!/bin/sh 

    # For more info about endpoint references, visit: 
    # https://developer.spotify.com/web-api/endpoint-reference/ 

    token=$(./spotifyAccess.php | jq '.access_token' | sed 's/\"//g') # where spotifyAccess.php genereates my access token 

    read -p "Please enter a method of authentification (e.g. GET, PUT, POST) " method 
    read -p "Please enter an endpoint (e.g. /v1/audio-features/{id}) " endpoint 
    read -p "Please enter a Spotify ID (e.g.2vEQ9zBiwbAVXzS2SOxodY) " id 

    url=$"https://api.spotify.com/$endpoint" 

    url=$(echo $url | sed "s/{id}/$id/g") 

    echo "My URl is: $url" 

    curl -X $method $url -H "Authorization: Bearer $token" 

これは私の初めてのスクリプトでカールを使用して、多分何か間違っていますか?今、私がスクリプトを実行すると、何も起こりません。

EDIT:@skr勧告に従い

、私は私のスクリプトにデバッグオプションset -xを追加しました。出力は次のようになります。

HTTP/1.1 404 Not Found 
Server: nginx 
Date: Tue, 08 Aug 2017 21:19:05 GMT 
Content-Length: 0 
Connection: keep-alive 
Keep-Alive: timeout=600 
Cache-Control: private, max-age=0 
Access-Control-Allow-Origin: * 
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE 
Access-Control-Allow-Credentials: true 
Access-Control-Max-Age: 604800 
Access-Control-Allow-Headers: Accept, Authorization, Origin, Content-Type 

答えて

1

それはあなたのプロンプトがまた

url=$"https://api.spotify.com/$endpoint" 
を含む第1のスラッシュが含まれているので、この行は間違って見えます
1

bashスクリプトで出力をチェックしてください。

#!/bin/sh 

#debug option 
set -x 

# For more info about endpoint references, visit: 
# https://developer.spotify.com/web-api/endpoint-reference/ 

token=$(./spotifyAccess.php | jq '.access_token' | sed 's/\"//g') # where spotifyAccess.php genereates my access token 

read -p "Please enter a method of authentification (e.g. GET, PUT, POST) " method 
read -p "Please enter an endpoint (e.g. /v1/audio-features/{id}) " endpoint 
read -p "Please enter a Spotify ID (e.g.2vEQ9zBiwbAVXzS2SOxodY) " id 

url=$"https://api.spotify.com/$endpoint" 

url=$(echo $url | sed "s/{id}/$id/g") 

echo "My URl is: $url" 

curl -X $method $url -H "Authorization: Bearer $token" 
関連する問題