0
我試圖在命令行上爲last.fm上的某個播放列表添加一個「藝術家 - 歌曲」條目。Last.fm無效方法簽名(playlist.addTrack)
我申請了一個API密鑰並獲得了一個會話密鑰,如last.fm API documentation中所述。我使用user.getplaylist($ PLID)獲得播放列表ID。
該服務需要客戶端發送數據作爲寫入任何方法的POST請求。對於我已決定使用捲曲-d
這裏是add_track.sh的內容:
SERVICE=http://ws.audioscrobbler.com/2.0/
APIKEY=1dfdc3a278e6bac5c76442532fcd6a05 # mpc-last
SECRET=<md5hash: api secret>
LASTFM_USER=<string: myuser>
LASTFM_SK=<md5hash: valid session key>
# parameters (sorted alphabetically becasue method signature requires them to be)
# api_key (Required) : A Last.fm API key.
# api_sig (Required) : A Last.fm method signature. See authentication for more information.
# artist (Required) : The artist name that corresponds to the track to be added.
# method playlist.addTrack
# playlistID (Required) : The ID of the playlist - this is available in user.getPlaylists.
# sk (Required) : A session key generated by authenticating a user via the authentication protocol.
# track (Required) : The track name to add to the playlist.
METHOD=playlist.addtrack
ARTIST=prodigy
TRACK=breathe
PLID=8698647
MS="api_key${APIKEY}" # api_sig can't be here because it's not produced yet, obviously
MS="${MS}artist${ARTIST}" MS="${MS}method${METHOD}" MS="${MS}playlistid${PLID}" # tried with playlistID too
MS="${MS}track${TRACK}"
#MS="${MS}sk${LASTFM_SK}" # including this does not help
MS="${MS}${SECRET}"
# hash it
MS=`echo -n $MS | md5sum | cut -d' ' -f1`
# call the service.
# args also sorted alphabetically, but this should definitely not matter
curl \
-d api_key=${APIKEY} \
-d api_sig=${MS} \
-d artist=${ARTIST} \
-d method=${METHOD} \
-d playlistID=${PLID} \
-d sk=${LASTFM_SK} \
-d track=${TRACK} \
$SERVICE
然後調用該服務:
$ ./add_track.sh
<?xml version="1.0" encoding="utf-8"?>
<lfm status="failed">
<error code="13">Invalid method signature supplied</error></lfm>