In the first part of this tutorial, I pulled a couple of variables from the XML feed of my Google Reader’s “starred items”. Now I wanted to “process” the item and UnStar it. This was not easy for me to put together – it was my first attempt at working with the Google API.
First I needed to get authenticated against Google Services for accessing Google Reader. Here is the shell script to do this:
stty -echo read -p "Password: " password; echo stty echo RESULT=$(curl -s https://www.google.com/accounts/ClientLogin \ --data-urlencode Emailemail@example.com --data-urlencode Passwd=$password \ -d accountType=GOOGLE \ -d source=MyAppName \ -d service=reader)
This returned some html that included the AUTH code that I needed to add to the header of each Google Reader Request. I used this AUTH to get a Token (my understanding is that if I wanted to edit an item, I needed the token too). Here are the two pieces of code to parse the AUTH get the Token:
AUTH=$(echo "$RESULT" | grep 'Auth=' | sed s/Auth=//) TOKEN=$(curl -s --header "Authorization: GoogleLogin auth=$AUTH" http://www.google.com/reader/api/0/token)
Putting the AUTH together with the Token, and the Source and id from this post, you end up with a cURL command that can mark an item as UnStared:
curl -s http://www.google.com/reader/api/0/edit-tag?client=MyAppName --request POST --header "Authorization: GoogleLogin auth=$AUTH" \ --data-urlencode r=user/-/state/com.google/starred \ --data-urlencode async=true \ --data-urlencode s=$SOURCE \ --data-urlencode i=$OBJID \ --data-urlencode T=$TOKEN
I was surprised when i got this to work. I am still scared of APIs/REST.