How can I programmatically send a note to Google Reader?

I use my notes in Google Reader as a place to store bookmarks and small pieces of information. I would like to write a small script so that I can send notes from the command line (I prefer Python, but the answer in any language will be accepted).

This project seemed to be a good place to start and even more relevant information here . The process is as follows:

So ... step 2 above always fails for me (get the 403 ban), and trying Martin C # House code has the same problem. It looks like Google no longer uses this method for authentication.

Refresh ... This comment launched me. Now I can log in and get a token. Now I just need to figure out how to send a message. My code is below:

import urllib2

# Step 1: login to get session auth 
email = 'myuser@gmail.com'
passwd = 'mypassword' 

response = urllib2.urlopen('https://www.google.com/accounts/ClientLogin?service=reader&Email=%s&Passwd=%s' % (email,passwd))
data = response.read()
credentials = {}
for line in data.split('\n'):
    fields = line.split('=') 
    if len(fields)==2:
        credentials[fields[0]]=fields[1]
assert credentials.has_key('Auth'),'no Auth in response'

# step 2: get a token
req = urllib2.Request('http://www.google.com/reader/api/0/token')
req.add_header('Authorization', 'GoogleLogin auth=%s' % credentials['Auth'])
response = urllib2.urlopen(req)

# step 3: now POST the details of note

# TBD...
+4
source share
1 answer

Using Firebug, you can see what will be sent if you add a Google Reader note from the browser.

URL-, , : http://www.google.co.uk/reader/api/0/item/edit.

, "T" ( 2) "", , .

, ( urllib, ):

# step 3: now POST the details of note

import urllib

token = response.read()
add_note_url = "http://www.google.co.uk/reader/api/0/item/edit"
data = {'snippet' : 'This is the note', 'T' : token}
encoded_data = urllib.urlencode(data)
req = urllib2.Request(add_note_url, encoded_data)
req.add_header('Authorization', 'GoogleLogin auth=%s' % credentials['Auth'])
response = urllib2.urlopen(req)

# this part is optional
if response.code == 200:
    print 'Gadzooks!'
else:
    print 'Curses and damnation'

, , . ck, linkify, share .., .

script .

+2

All Articles