Topsy から Google+ の検索結果を JSON で取得

今朝(米国時間10/11)、リアルタイム検索・分析プラットフォームを提供するTopsy LabsがGoogle+を検索対象に含めたことを発表した。

Google+の公開投稿専用の検索エンジン(ベータ版)はこちら〔日本語版〕。ユーザーはGoogle+への公開投稿をリアルタイムでも過去に遡っても検索できる。

via. Topsy、Google+一般公開投稿のリアルタイム検索エンジンをローンチ〔日本語にも対応ずみ〕

Topsy から特定 URL の Google+ 検索結果を JSON で取得するには

http://plus.otter.topsy.com/trackbacks.json?url={url}&tracktype=googleplus__trackback

ちなみに特定 URL の Twitter の Tweet を取得するには

http://otter.topsy.com/trackbacks.json?url={url}&tracktype=tweet

PHP で JSON を処理する

$request_url = 'http://search.twitter.com/search.json?lang=ja&q=ohayo';
$ch = curl_init($request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$jsonData = curl_exec($ch);
curl_close($ch);

$jsonData = json_decode ($jsonData, true);

foreach($jsonData->results->from_user_id_str as $r) {
    $usr = $jsonData->results->from_user;
    $text = $jsonData->results->text;
    $c_at = $jsonData->results->created_at;

    $img = '<img src=\"'.$results->profile_image_url.'\">';
    $post = $img."<br />"."<strong>".$usr."</strong>(".$c_at.")<br />".$text."<br />";
}

via Twitter検索のJSONを読みたいのですがどうすればいいのでしょう? - Yahoo!知恵袋

json_decode の第二引数を true にすると、連想配列で結果を返すし、false(デフォルト)にするとオブジェクトで結果を返すよ。

そもそも、foreach の中にもバグが有る。

$request_url = 'http://search.twitter.com/search.json?lang=ja&q=ohayo';
$jsonData = file_get_contents($request_url);
$jsonData = json_decode($jsonData);
foreach($jsonData->results as $r) {
        $usr  = $r->from_user;
        $text = $r->text;
        $c_at = $r->created_at;

        $img  = "<img src=\"$profile_image_url\">";
        $post = "$img<br /><strong>$usr</strong>($c_at)<br />$text<br />";
}

フォロー

Get every new post delivered to your Inbox.

現在1,816人フォロワーがいます。