Search code examples
apicurlgoogle-music

Google Music API: how to request the next 1000 songs?


I'm trying to figure out how to use Google Music API. I managed to get the auth token as described in http://dpogue.ca/gmusic.html:

$ curl -d accountType=GOOGLE
       -d Email=jondoe@gmail.com    
       -d Passwd=<<PASSWORD>>
       -d service=sj
       https://www.google.com/accounts/ClientLogin

SID=DQB...
LSID=DQC...
Auth=DQA...

Now I'm able to request the list of tracks in my library:

$ curl --header "Authorization: GoogleLogin auth=DQA..."     
       https://www.googleapis.com/sj/v1beta1/tracks > list

However, it only returns a list of 1000 tracks.

$ grep -c albumArtist list
1000

How do I request the next 1000 tracks? I've tried to append the nextPageToken to the URL:

$ grep nextPage list
"nextPageToken": "KmM...AI="
$ curl --header "Authorization: GoogleLogin auth=DQA..."     
       https://www.googleapis.com/sj/v1beta1/tracks?pageToken=KmM...AI= > list2

but I just get the same first 1000 tracks.

How do I tell googleapis.com to return the next bunch?

Thanks!


Solution

  • First, I was advised to use a different URL: https://www.googleapis.com/sj/v1beta1/trackfeed

    The correct way to provide nextPageToken to the second request is now to send it per POST as JSON:

    $ curl
      --header "Authorization: GoogleLogin auth=DQA..."     
      --header 'Content-Type: application/json'
      --data "{'start-token': 'KmM...'}
      "https://www.googleapis.com/sj/v1beta1/trackfeed
      > list2
    

    For me it turned out to be even easier to request all tracks at once by providing

      --data "{'max-results': '20000'}
    

    Thanks to Darryl Pogue from http://dpogue.ca/!