LoginSignup
3
3

More than 5 years have passed since last update.

Google Feed APIで取得できるエントリーの内容

Last updated at Posted at 2015-08-18

結構前からGoogle news APIが廃止されてFeed APIを使ってくださいねって感じになっているのですが、じゃあ、Feed APIで何が取得できるのか調べてみた

使い方


jquery読み込んでAPI取得して処理を書きます。

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>

<script type="text/javascript">

google.load("feeds", "1");
function initialize() {

    //検索クエリ
    var query = ""
    //フィードの取得 
    var feed = new google.feeds.Feed("https://news.google.com/news?output=rss&q=" + query);

    //取得するエントリ数
    feed.setNumEntries(10);

    //フィードを取得した時の処理
    feed.load(function(result) {
        if (!result.error) {
            for (var i = 0; i < result.feed.entries.length; i++) {
                //これが1つの記事
                var entry = result.feed.entries[i]
            }
        }
    });

}

//ロードされたタイミングでinitializeメソッドを実行?
google.setOnLoadCallback(initialize);

</script>

entriesの中身はなんなのか


entriesに含まれているのはオブジェクトで、内容は以下のとおりである。

author: 記事の執筆者?
categories: 配列。記事のカテゴリが含まれる?
content: titleやlink, authorなどが全て含まれたDOM要素
contentSnippet:contentの最初の部分から一定の文字数を取り出し、最後に「...」で締められている文字列
link: 記事へのリンク
publishedDate: "Sun, 16 Aug 2015 18:47:42 -0700"という感じの形式で、記事の書かれた日時。
title: 記事のタイトル

?のついてるものは自分の場合は空要素だったので、詳細は不明、多分公式サイトに掲載されているので後で確認して修正する。

調べたところだと、特にAPIキーも求めてこないし、取得数の制限も特に決められてない?ようなので、何かに使えそう。

追記

コメントでご指摘頂きました。取得できるのは1000件/日くらいだそうです。ご指摘ありがとうございました。

3
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3