如何使用Python通过Google Reader API将项目标记为已读
我用下面这个Python函数来标记Google Reader里的一个项目为已读,但它总是返回错误: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()
其他的函数可以成功获取订阅和条目,所以问题不是像用户名或密码错误这种基本的错误。我看到说需要进行URL编码,所以我也做了。一个示例的entryid看起来是这样的:tag:google.com,2005:reader/item/f66ad0fb64f56a22。
我到底哪里做错了呢?
2 个回答
0
当我把这个和我在Firefox中发出的请求进行比较(用liveheaders检查过),看起来是没问题的。我只是多了一些额外的参数。
async=true
sync=true
s=feed/http://feeds.feedburner.com/37signals/beM
而在用户那一部分,-
的位置上应该是一个很长的ID。
所以你可以试着加上这两个同步参数,添加s参数,并且把-
替换成一个ID。
至于你正在做的URL编码,看起来也是没问题的。
2
看起来你缺少了身份验证的头信息:
header = {
'Content-type': 'application/x-www-form-urlencoded',
'Authorization': 'GoogleLogin auth=YOUR_AUTH_TOKEN'
}