PHPではてなブックマークエントリー取得情報APIを使う

参考
はてなブックマークエントリー情報取得APIとは - はてなキーワード
PHP: インストール手順 - Manual
PHP: cURL 関数 - Manual

環境

OS :Ubuntu 10.04
PHP:php5, php5-cli

getHatenar.php

<?php
/* はてなブックマークエントリー情報取得APIを用いてブックマーク情報を取得する
 * "http://www.hatena.ne.jp/"の情報を取得するサンプル
 */

// curlを利用するためには以下のコマンドでインストールが必要
// $ sudo apt-get install php5-curl

// とりあえず関連エントリーは使わないので,より高速なレスポンスの /entry/jsonlite/ を利用 
$c = curl_init("http://b.hatena.ne.jp/entry/jsonlite/http://www.hatena.ne.jp/");
// curl_exec()の返り値を文字列で返すためのパラメータ
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($c);
curl_close($c);

$jsonObj = json_decode($json);

// 表示
var_dump($jsonObj);

// 各要素には以下の様に参照する
/*
echo 'title:' . $jsonObj->title . "\n";
echo 'count:' . $jsonObj->count . "\n";
echo 'url:' . $jsonObj->url . "\n";
echo 'entry_url:' . $jsonObj->entry_url . "\n";
echo 'screenshot:' . $jsonObj->screenshot . "\n";
echo 'eid:' . $jsonObj->eid . "\n";
foreach($jsonObj->bookmarks as $k => $bv){
	echo $k . "\n";
	echo 'timestamp:' . $bv->timestamp . "\n" ;
	echo 'comment:' . $bv->comment . "\n";
	echo 'user:' . $bv->user . "\n";
	echo 'tags:';
	foreach($bv->tags as $tv){
		echo $tv . ' ';
	}
	echo "\n";
}
*/
?>

実行

$ php getHatenar.php
object(stdClass)#1 (7) {
  ["count"]=>
  string(4) "3935"
  ["bookmarks"]=>
  array(2696) {
    [0]=>
    object(stdClass)#2 (4) {
      ["timestamp"]=>
      string(19) "2010/06/04 18:44:07"
      ["comment"]=>
      string(0) ""
      ["user"]=>
      string(10) "shuuheihei"
      ["tags"]=>
      array(0) {
      }
    }
    [1]=>
    object(stdClass)#3 (4) {
      ["timestamp"]=>
      string(19) "2010/06/03 23:58:24"
      ["comment"]=>
      string(0) ""
      ["user"]=>
      string(8) "kinneko2"
      ["tags"]=>
      array(1) {
        [0]=>
        string(15) "webサービス"
      }
・
・
・
    [2695]=>
    object(stdClass)#2697 (4) {
      ["timestamp"]=>
      string(19) "2004/12/22 01:52:20"
      ["comment"]=>
      string(0) ""
      ["user"]=>
      string(10) "kalamucho1"
      ["tags"]=>
      array(2) {
        [0]=>
        string(2) "PC"
        [1]=>
        string(11) "PC DIY Info"
      }
    }
  }
  ["url"]=>
  string(24) "http://www.hatena.ne.jp/"
  ["eid"]=>
  string(3) "370"
  ["title"]=>
  string(9) "はてな"
  ["screenshot"]=>
  string(95) "http://screenshot.hatena.ne.jp/images/200x150/c/2/6/b/d/f015f87fcf44a513f4744d853fe22504bc3.jpg"
  ["entry_url"]=>
  string(45) "http://b.hatena.ne.jp/entry/www.hatena.ne.jp/"
}

こんな感じ
変なところあったら指摘お願いしますー