curl을 사용하여 Spotify API에 액세스하려고합니다. 나는 터미널에서 한 라이너로 이것을 할 수 있고 잘 작동합니다. 예를 들면 :
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"
스크립트에서 curl을 사용하는 것은 이번이 처음입니다. 제가 뭔가 잘못하고있는 것일까 요? 지금 스크립트를 실행해도 아무 일도 일어나지 않습니다.
편집하다:
@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
이 줄은 프롬프트에 포함 된 첫 번째 슬래시를 포함하므로 잘못 보입니다.
url=$"https://api.spotify.com/$endpoint"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다