注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

又一个部落格

换过很多备忘录,不知道这本怎么样!

 
 
 

日志

 
 

google reader api  

2010-06-06 01:27:46|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
这里我们要理解,为什么我们用google read,而不直接使用网站的rss, 因为
1. rss有非常多的版本,大约10来个, 我们要写一个能够正确解析他们的通用程序是有难度的. google为我们做了这一步.google返回给我们的都是统一的格式
2. 有些rss被zf屏蔽,我们无法直接访问,通过google, 起到翻墙作用
3. 一些rss接口只提供最新的n条信息, 想要获取早些时候的信息成为不可能,google会为我们缓存所有的信息
4. 假如我们的服务器直接去访问某个rss,速度会比较慢, 这个任务google来做, 速度明显会比较快


请求 google登录接口
https://www.google.com/accounts/ClientLogin
参数
POST parameter name POST parameter value
service 'reader' (可选)
Email google账号
Passwd 密码
source 客户端的标识 例如 Mobile Newspaper/0.1 (可选)
continue 'http://www.google.com/' (可选)

php代码
$curl = curl_init();
$datas = array(
'Email' => 'youname@gmail.com',
'Passwd' => 'pwd',
'service' => 'reader',
'source' => 'Mobile Newspaper/0.1',
'continue' => 'http://www.google.com/'
);

curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $datas);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_exec($curl);


返回值
SID=DQAAAIIAAADLOgquebmwAmluwdkqloneF3FvQAZZvG6EcPSqHLeXrBhfM1VFr2S36FT3C9YHNvzqjQl5ugBMlUgePDhtONnJujvUOrF11QV_DSg4I03b4HLndFnRQzZ2KmidxorykoB-3mf-gQH8NWmYOVYh-VXyM1Hursdr0tBatDDedQqs4R9CfZUzc9WV2erbKHmifF8
LSID=DQAAAIQAAACXQ9n7yPnAL7I18wEWQRx7lY4mssTO3aZ8NOn69h38fPBPzehq2jMyDIlqyetB2wVqu9_GKBxEwPbokfL-89a0hrXUNNFp4RQbV2tKiiuIGIcPLGA6n8mkkn4-4E3TxCnxSzvSiX1Pt2Q4zUhifDzSZ2NHZLw2TCXotsdpHpy18raGnWto3FoVSyxYe9EAafA
Auth=DQAAAIUAAACXQ9n7yPnAL7I18wEWQRx7lY4mssTO3aZ8NOn69h38fPBPzehq2jMyDIlqyetB2wUc1Ls7OzGP0qnFCvjbIi1EZz_3kvNLcjIm9N_ZD5yFu0TxbJLUH3oskRAM5s8ffGQPKKtFEWzHqAAQLEO-R-BViHsVOuox5zbcFmeIQbGXoY1Hy1YkZnTWg5HeaIbIWAE


拿到返回值后,分离出 SID,下次请求就用这个SID请求
下次请求的请求头中需要包含下面4值
name SID
domain .google.com
path /
expires 1600000000


google read的接口都是从 http://www.google.com/reader/ 开始
http://www.google.com/reader/atom/ 返回atom 格式的rss
http://www.google.com/reader/api/0/ 这个是最主要的接口url,他包含了给某条信息打标记,也可以返回信息列表,返回tags列表,返回未读数量, 可以是xml,或者json返回格式
http://www.google.com/reader/view/ 显示用户相关信息的接口
http://www.google.com/reader/shared/ 分享rss使用的接口
http://www.google.com/reader/settings/ 用户设置接口


下面是 http://www.google.com/reader/atom/ 的几个url
feed/url of a feed ,这个url可以和我们的账号没有任何关系,就是一个rss地址
user/user ID/label/label name , 用账号中设置的某个label来请求
user/user ID/state/com.google/state ,请求某个状态下的信息,比如read,starred

一共下面有这些状态
read 已读
kept-unread Once you've clicked on "keep unread", an item will have the state kept-unread
fresh 新的
starred 标注了星号的
broadcast 公共的
reading-list All you items are flagged with the reading-list state. To see all your items, just ask for items in the state reading-list
tracking-body-link-used Set if you ever clicked on a link in the description of the item.
tracking-emailed Set if you ever emailed the item to someone.
tracking-item-link-used Set if you ever clicked on a link in the description of the item.
tracking-kept-unread Set if you ever mark your read item as unread.

假如像获取 rss http://xkcd.com/rss.xml 的信息 ,那么可以
http://www.google.com/reader/atom/feed/http://xkcd.com/rss.xml
假如要获取所有的最后阅读的信息可以
http://www.google.com/reader/atom/user/-/state/com.google/read

另外的一些get参数
n 返回信息条数,默认20
client 客户端表示,比如我们设置的Mobile Newspaper/0.1
r 排序,默认是按现在开始,然后时间的倒序排, 默认值 d,可以设置成 o
ot 开始时间的 时间戳 ,当 r=o 的时候有效 如果时间超过一个月之前,那么就被一个月前这个条件代替了
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
xt exclude_target another set of items suffix, to be excluded from the query. For exemple, you can query all items from a feed that are not flagged as read. This value start with feed/ or user/, not with !http:// or www
c continuation a string used for continuation process. Each feed return not all items, but only a certain number of items. You'll find in the atom feed (under the name gr:continuation) a string called continuation. Just add that string as argument for this parameter, and you'll retrieve next items.

返回前17条 来自 xkcd.com 的未读信息
http://www.google.com/reader/atom/feed/http://xkcd.com/rss.xml?n=17&ck=1169900000&xt=user/-/state/com.google/read


最主要的接口 http://www.google.com/reader/api/0/
这个接口有两个功能
edit 和list

edit api
要进行编辑, 首先要获取一个token
http://www.google.com/reader/api/0/token
这个接口返回 token ,57个字符的
有两个参数
get参数
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)

其他的edit接口都是用post发送参数的,除了一个参数用get
client client The default client name (see client in glossary)

假如失败,接口返回 "", 成功返回 "ok",假如失败,很可能是token过期,尝试去获取一个新的,如果还是失败,那么就真的失败了.

post参数表
API call function POST parameter name python Google Reader API name parameter value
subscription/edit
s feed The subscription feed name, in the form feed/...
t title The subscription title, used when adding a new subscription or when changing a subscription name
a add A label to add (a label on a subscription is called a folder) in the form user/...
r remove A label to remove (a label on a subscription is called a folder) in the form user/...
ac action The actions to do. Know values are edit (to add/remove label/forlder to a feed), 'subscribe', 'unsubscribe'
token token The mandatory up to date token
tag/edit
s feed The tag/folder name seen as a feed
pub public A boolean string true or false. When true, the tag/folder will become public. When false, the tag/folder will stop being public.
token token The mandatory up to date token
edit-tag
i entry The item/entry to edit, in the form tag:google.com,2005:reader/item/... ( it's the xml id of the entry tag of the atom feed)
a add A label/state to add (a label on an item/entry is called a tag) in the form user/...
r remove A label/state to remove (a label on an item/entry is called a tag) in the form user/...
ac action The actions to do. Know value is edit (to add/remove label/forlder to a feed)
token token The mandatory up to date token
disable-tag
s feed The tag/folder name seen as a feed
ac action The actions to do. Know value is disable-tags (to remove a tag/folder)
token token The mandatory up to date token


例子 :
新增一个rss地址:
http://www.google.com/reader/api/0/subscription/edit?client=contact:myname-at-gmail
with POST arguments : s=http://xkcd.com/rss.xml&ac=subscribe&token=here-put-a-valid-token

移动到某个rss到文件夹:
http://www.google.com/reader/api/0/subscription/edit?client=contact:myname-at-gmail
with POST arguments : s=http://xkcd.com/rss.xml&ac=edit&a=user/-/label/comics&token=here-put-a-valid-token

list api
所有的参数都是get的
API call function GET parameter name python Google Reader API name parameter value/API call description
tag/list Get the tag list and shared status for each tag.
output output The format of the returned output. may be 'json' or 'xml'
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)
subscription/list Get the subscription list and shared status for each tag.
output output The format of the returned output. may be 'json' or 'xml'
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)
preference/list Get the preference list (configuration of the account for GoogleReader).
output output The format of the returned output. may be 'json' or 'xml'
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)
unread-count Get all the information about where are located (in term of subscriptions and tags/folders) the unread items.
all all 'true' if whole subscriptions/tags are required. (TODO: Needs to check other values)
output output The format of the returned output. may be 'json' or 'xml'
ck timestamp current time stamp, probably used as a quick hack to be sure that cache won't be triggered.
client client The default client name (see client in glossary)




Viewer http://www.google.com/reader/view/
这个接口其实是 http://www.google.com/reader/atom/ 返回的html版本
比如要获取 important 标签下的 http://www.google.com/reader/view/user/-/label/important
http://www.google.com/reader/view/feed/http://xkcd.com/rss.xml



参考: http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
  评论这张
 
阅读(2291)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017