RSS

Category Archives: YQL

利用Google Reader API 抓全部RSS歷史資料

有時候想說看到有些不錯的Blog,習慣動作就會找有沒有RSS Feed可以訂閱,方便以後作者更新時能第一時間知道,不過,如果想要一次把所有歷史資料找出來,還要回到原本的網站去慢慢點回去,於是我開始找有沒有方法可以像是Google Reader一樣可以看到之前的資料,目前找到一個比較簡單的方法是,直接呼叫Google Reader API,目前Google還沒有正式開放使用,所以找到的資料都是方官方資訊,不過大體上還換清楚,唯一的限制是,要從Google Reader API 撈的資料,必須有人已經在Google訂閱過,Google才有庫存的資料能提供

舉例來說,PTT笨版的RSS是 http://rss.ptt.cc/StupidClown.xml

所以如果你想要從Google Reader APi抓的話只需要輸入

『  http://www.google.com
/reader/api/0/stream/contents/feed/http://rss.ptt.cc/StupidClown.xml?n=20
  』

以上網址會回傳JSON的格式,另外還有一些參數可以利用。

  • ot=[unix timestamp] : The time from which you want to retrieve items. Only items that have been crawled by Google Reader after this time will be returned.
  • r=[d|n|o] : Sort order of item results. d or n gives items in descending date order, o in ascending order.
  • xt=[exclude target] : Used to exclude certain items from the feed. For example, using xt=user/-/state/com.google/read will exclude items that the current user has marked as read, or xt=feed/[feedurl] will exclude items from a particular feed (obviously not useful in this request, but xt appears in other listing requests).
  • n=[integer] : The maximum number of results to return.
  • ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
  • client=[your client] : You can use the default Google client (scroll), but it doesn’t seem to make a difference. Google probably uses this field to gather data on who is accessing the API, so I’d advise using your own unique string to identify your software.

以上轉貼 Using the Google Reader API – Part 2

基本上有了上面的API,大部分的事情幾乎都能做了,但是如果想用 JavaScript 來呼叫JSON,會有Cross-Domain的問題,為了解決瀏覽器先天的限制,我搜尋了一下解法,JSONP、document.domain、Web Proxy、Iframe proxying 都可以解,這邊選擇 Yahoo! 查詢語言 (Yahoo! Query Language, YQL來呼叫Google Reader API 來解決,YQL提供callback function 解決Cross-Domain問題。

YQL介紹也蠻多的,Yahoo也提供相當多的資訊與範例,官方資訊至今算是相當完整,以下範例是我利用Online Editor(JSFIDDLE), 利用YQL去呼叫 Google Reader API寫的範例,如果要看舊資料可以試著調整參數, ex: n=1000 之類的。

Sample Code

2011 04 15
ps: sample code 目前有點問題,週末會在更新

2011 04 17
● 解決 IE8以後cross-domain 配合AJAX去抓JSONP的問題,FF CH 目前測試也OK.
● 整合Google Reader API “continuation” 參數去遞迴撈資料,舉例像是 ppt 的RSS能達高達上萬筆歷史資料,sample 上方MAX參數調整太大可能會抓很久的時間.
● 目前設定一次跟API要100筆資料,Google Reader 目前最高一次可以回傳1000筆,建議不要超過300筆,有些RSS內容太多,YQL會回傳null 導致失敗,原因不明,有需要可以改source 變數 “numberOfReturn".
● Sample Code是純hml ,只有線上參考jQuery ,可以直接檢視原始檔拿去改。
● Sample Code 上方加上 Feed in Google & YQL JSON 兩個連結去測試輸入的RSS Feed有沒有在被庫存在google.
● 提供點選連結可以看summary,如果按了沒有反應表示沒資料,最後,整體畫面很簡單,希望大家不要嫌棄.

2014 09 11
最近在整理文章,Google Reader 已經停止服務了,Reader API也不能使用。

 

參考資料:

Have fun.

 
發表迴響

發文者為 於 2011 年 04 月 14 日 英吋 coding, Google Reader API, jQuery, JSON, YQL