Last.fm invalid method signature (playlist.addTrack)
I am trying to add an "artist - song" entry to one of my playlists on last.fm from the command line.
I applied for an API key and got a session key as described in the last.fm API documentation. I got a playlist id using user.getplaylist ($PLID).
The service requires clients to send data as a POST request for methods that write anything. For that I have decided to use curl -d
Here are the contents of 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 (Requi开发者_运维技巧red) : 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
Then i call the service:
$ ./add_track.sh
<?xml version="1.0" encoding="utf-8"?>
<lfm status="failed">
<error code="13">Invalid method signature supplied</error></lfm>
For reference:
curl -v \
-d "api_key=`perl -e 'use Encode; printf "%s", encode_utf8($ARGV[0])' ${APIKEY}`" \
-d "api_sig=`perl -e 'use Encode; printf "%s", encode_utf8($ARGV[0])' ${MS}`" \
-d "artist=`perl -e 'use Encode; printf "%s", encode_utf8($ARGV[0])' ${ARTIST}`" \
-d "method=`perl -e 'use Encode; printf "%s", encode_utf8($ARGV[0])' ${METHOD}`" \
-d "playlistID=`perl -e 'use Encode; printf "%s", encode_utf8($ARGV[0])' ${PLID}`" \
-d "sk=`perl -e 'use Encode; printf "%s", encode_utf8($ARGV[0])' ${LASTFM_SK}`" \
-d "track=`perl -e 'use Encode; printf "%s", encode_utf8($ARGV[0])' ${TRACK} `" \
$SE
.... one is probably better off using perl from the beginning: http://www.easyclasspage.de/lastfm/seite-11.html
精彩评论