7

I use the following python function to mark an item as read in google reader, but it always returns error HTTPErrors: HTTP 401: Unauthorized:

def mark_as_read(SID, entryid):  
    token = get_token(SID)  
    mark_as_read_url = 'http://www.google.com/reader/api/0/edit-tag'  
    header = {'Content-type': 'application/x-www-form-urlencoded'}  
    post_data = urllib.urlencode({ 'i': entryid, 'a': 'user/-/state/com.google/read', 'ac': 'edit', 'T': token })  
    request = urllib2.Request(mark_as_read_url, post_data, header)  
    f = urllib2.urlopen(request)  
    result = f.read()

Other functions are successfully retrieving feeds and entries , so it's not something basic like a wrong username or password. I've read that urlencoding is required, so I've done that. A sample entryid looks like this: tag:google.com,2005:reader/item/f66ad0fb64f56a22

What am I doing wrong?

Ned Ryerson
  • 101
  • 4
  • 1
    This is a POST, and the examples you use of successful requests sound like GETs. Do you have other successful POSTs? Perhaps there's some difference between the two in this API that you haven't got right yet? PS: Neds Unite! – Ned Batchelder Nov 08 '09 at 13:17
  • I was accessing Google Reader this same way using Perl, and everything works good for me except changing the state of items (Marking as read, starring, etc). Listing items in Reader works fine for me... I have a feeling this could be something on the Google end, or maybe the unofficial API is not up-to-date on how to mark items as read? – BrianH Jun 11 '10 at 19:29
  • is there an update on this. I also need to implement mark as read in a python app. thanks – Vaibhav Garg Jul 16 '10 at 07:23

2 Answers2

2

It seems you are missing the authentication header:

header = {
    'Content-type': 'application/x-www-form-urlencoded',
    'Authorization': 'GoogleLogin auth=YOUR_AUTH_TOKEN'
}
coryjacobsen
  • 998
  • 2
  • 9
  • 10
0

When i compare this to the request I'm making in Firefox (inspected with liveheaders), it looks ok. I only have the extra parameters

async=true
sync=true
s=feed/http://feeds.feedburner.com/37signals/beM

And in the user, on the place of - there is a long id.

So you could try adding the two sync parameters, adding the s parameter, and filling in an id for the -.

With regard to the urlencoding you're doing, that seems to be ok.

markijbema
  • 3,985
  • 20
  • 32