ܻؤ1顪30奵꡼ޥܥ

ITȤƯ30奵꡼ޥΥ饤ߥ󥰵Ͽ

API

zoomeư򥿥Ǹ

ǶΥưϤäѤzoomeǤ͡
̥礭̤礭ӥåȥ졼Ȥ⤤
˥ưήƤƤ褦˻פޤ
Ȥ櫓ǡzoomeΥPHPǡ

require_once 'XML/RPC.php';

$arr = array('tagname' => '',
             'offset' => 0,
             'length' => 10
             );
$params  = new XML_RPC_Value(array(
                                   'tagname' => new XML_RPC_Value($arr['tagname'], 'string'),
                                   'offset' => new XML_RPC_Value($arr['offset'], 'i4'),
                                   'length' => new XML_RPC_Value($arr['length'], 'i4'),
                                   ), "struct");

$msg = new XML_RPC_Message('zoome.tagSearch', array($params));
$cli = new XML_RPC_Client('/xmlrpc', 'up.zoome.jp', 80);
$res = $cli->send($msg);

if (!$res->faultCode()) {
  $data = XML_RPC_decode($res->value());
  /* "Total:". $data['count']; */
  foreach($data['list'] as $key => $val) {
    $zoome = array(
                   'zoomeid' => $val['zoomeid'],
                   'diaryid' => $val['diaryid'],
                   'title' => $val['title'],
                   'url' => $val['diaryurl'],
                   'body' => $val['body'],
                   );
  }
} else {
  exit('CODE:'.$res->faultCode(). ':'. $res->faultString());
}


ߤ򤤤ХȤۤǤ͡
ǥեȤǿȻפǤɡΥȤ餤Ϥۤʡ
¾ˤƤȤΥ᥽åɤΤǸɥȤ򻲾ȤƤߤƤ

͡zoome API(XML-RPC)ɥ
    Υȥ꡼ϤƤʥ֥åޡɲ

ʥ֥AtomAPIݤʤε
ϸƤäѤƱ褦˺äƤͤߤ

Ȥ櫓ǡפ֤Ĵľ
ΥȰ㤦ʬԥååס
äѤWSSEǧݥȤǤ줵̤ФȤϤʤꡣ


$nonce = sha1(md5(time()));


ʸ鲿Ǥ⤤Ȥϻפɡ


$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.strtolower(md5($password)))));


դä
ʸˤ󤸤ʤʸˤ롣


Ȥgetǵη̤postURLȤäƵꤲߤ

Ѥ
³ɤ
    Υȥ꡼ϤƤʥ֥åޡɲ

äĴ٤뤳ȤäΤǡȤƻĤƤޤ

ܸtweetˡϤȤ⤦ɡ
ϥեAPIǥ桼κǿΥơ뤳Ȥ顢
ͭ̾ͤΥեtweet򽸤ʿͤФƤߤ褦ȡ

֤׳ŪˤɤΤ餤tweetʿͤȤפȤƿѤǤͤȤäƤϤ͡
ä褦ʽʤä褦ʵ뤱ɡȤꤢŬʿȤäƤߤޤ

åȤȤͭ̾ͤϾ֤
֤ΥեAPIǼʿͤޤ

äȸŤAPIλ͸Ƥpage=1Ȥǥڡꤹäƽ񤤤ƤɡΥɥȸcursorˤʤäƤ
̵̤˥ϥޤä

ͤcursor=-1ꤷơ쥹ݥ󥹤next_cursor֤äƤΤǼΥڡ򸫤ȤϤͤꤹ롣
פcursor=1,2,3Ȥʤߤ

˽񤤤ƤñʥХåäƤߤȤ
оTweet6587tweet
ȡʸ234153ʸ
ʿTweetʸ35.5ʸ
ʾΤ褦ʷ̤ˡ
*)RTǻϤޤäƤtweetϽޤ

٤äƤߤƤ30ʸäΤǡ
ܿͤ3040ʸǤĤ֤䤤ƤǤ礦֤

tweetLength.php

<?php
$username = "USERNAME";
$password = "PASSWORD";
$target = 'kazuyo_k';

$tweet=0;
$length=0;
$cursor = -1;
for ($i=0;$i<150;$i++) {
  if ($cursor == 0) break 1;

  $url = sprintf("http://twitter.com/statuses/followers.json?cursor=%d&screen_name=%s",$cursor,$target);
  $json = request($url,$username,$password);
  if (!is_array($json->users)) continue 1;
  foreach ($json->users as $key => $val) {
    if(isset($val->status)) {
      //RTǻϤޤtweetФ
      if(preg_match("/^RT(.+)/",$val->status->text)) continue 1;

      if (mb_detect_encoding($val->status->text) != 'UTF-8') continue 1;
      $tweet++;
      $length+=mb_strlen($val->status->text, 'utf-8');
    }
  }
  $cursor = $json->next_cursor;
}
echo "tweet  : " . $tweet . "\n";
echo "length : " . $length . "\n";
echo "avg    : " . $length / $tweet . "\n";

function request($host='',$username='',$password=''){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $host);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
  curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  $result = curl_exec($ch);
  curl_close($ch);

  return json_decode($result);
}
?>
    Υȥ꡼ϤƤʥ֥åޡɲ

ʤ󤫤ΤȤʤΤǥԥѥ⡣
jQueryȤäjsonpǥǡ
Ȥꤢ饤֥ˤƻȤȤɤ߹फ󤸤ˡ

bitlyApi.js

BitlyClient = function() {
  this._initialize();
}
$.extend(BitlyClient.prototype, {
  _initialize: function(login, apikey, version) {
    this.login = login || "LOGIN";
    this.apikey = apikey || "APIKEY";
    this.version = version || "2.0.1";
  },
  shorten: function(longUrl, target) {
    var result;
    $.ajax({
      type: "GET",
      url: "http://api.bit.ly/shorten",
      data: {
        "login": this.login,
        "apiKey": this.apikey,
        "version": this.version,
        "longUrl": longUrl
      },
      dataType: "jsonp",
      success: function(data) {
        for (var r in data.results) {
          result = data.results[r];
          break;
        };
        target.text(result.shortUrl);
      }
    });
  },
  expand: function(shortUrl, target) {
    var result;
    $.ajax({
      type: "GET",
      url: "http://api.bit.ly/expand",
      data: {
        "login": this.login,
        "apiKey": this.apikey,
        "version": this.version,
        "shortUrl": shortUrl
      },
      dataType: "jsonp",
      success: function(data) {
        for (var r in data.results) {
          result = data.results[r];
          break;
        };
        target.text(result.longUrl);
      }
    });
  }
});
var Bitly = new BitlyClient();


URLȥåϤƽϤ饤֥ʤΤǻȤӤ˹碌ơ
ȤꤢURLϤƽϤ㡣

html

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>
<script src="bitlyApi.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
  $('input[id^=bitly]').click(function() {
    eval("Bitly."+$(this).val()+"($('input#url').val(), $('div#bitly-result'))");
  });
});
</script>
</head>
<body>
<input type="text" id="url" /><input type="button" value="shorten" id="bitly-shorten" /><input type="button" value="expand" id="bitly-expand" />
<div id="bitly-result"></div>

    Υȥ꡼ϤƤʥ֥åޡɲ

ɤTwitterڤ٤
ʤˤڤΤޤ褯狼Τ
ʬǶ̣Ƥ褦APIȤäƥȺޤ
CakePHPͤơ

ECôäݤߤפ򥭡ɤ˽Ƥߤޤ

Ȥꤢ֤äѤʤߤǺäΤȤ겡ʴǤ


˾ʤ

˾ʤ

åäꡢ⤦äȥꥢ륿Ȳ¿ȻפΤǤܤܤޤ
    Υȥ꡼ϤƤʥ֥åޡɲ

livedoorBlogAtomAPI˰³֥ä㤦Ȼפäϥޤä
ƱAtomAPIƱǹԤȻפä㤦餷

Ĵ٤ƤߤWSSEǧڤȼݤ
Ǥ⤤Ĵ٤ƤƱ褦˺äƤͤϤƤ⡢褷ƤͤĤʤ

ɵݤޤ(2010-02-03)  >>εء



ޤĴ٤livedoorBlogȰ㤦Ȼפʬpass_digestκʬ

livedoorBlog
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.$password)));

֥
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.strtoupper(md5($password)))));

ѥɤmd5Ȥʸ餷Ȥξ
ǥޤۥȤ狼ޤ󡣡

֤äƤ쥹ݥ󥹤
CurlResponse Object
(
    [body] => 
X-WSSE authentication required
    [headers] => Array
        (
            [Http-Version] => 1.1
            [Status-Code] => 401
            [Status] => 401 Unauthorized
            [Set-Cookie] => BIGipServerPool_comment=3395622060.20480.0000; expires=Sat, 17-Oct-2009 01:32:13 GMT; path=/
            [Date] => Fri, 16 Oct 2009 02:18:33 GMT
            [Server] => Apache
            [Content-Length] => 83
            [Content-Type] => application/x.atom+xml
        )

)

ʤ󤫰㤦ȤǴְäƤΤ
Ѥɤϰʲ

³ɤ
    Υȥ꡼ϤƤʥ֥åޡɲ

ε˰³AtomAPIѡ
PHPcURLѡ

<?php
require_once 'cURL.php';

$atomapi_url = "http://cms.blog.livedoor.com/atom/";
$livedoor_id = "your livedoor id"; /* livedoorID */
$password = "your password"; /* ѥ */
$category = "1"; /* ƥ */
$title = "sample"; /* ȥ */
$text = "content"; /* ʸ */

$created = date('Y-m-d\TH:i:s\Z');
$nonce = pack('H*', sha1(md5(time())));
$pass_digest = base64_encode(pack('H*', sha1($nonce.$created.$password)));
$wsse =
  'UsernameToken Username="'.$livedoor_id.'", '.
  'PasswordDigest="'.$pass_digest.'", '.
  'Nonce="'.base64_encode($nonce).'", '.
  'Created="'.$created.'"';

$text64= base64_encode($text);

$rawdata =
  '<?xml version="1.0"?>'.
  '<entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">'.
  '<title type="text/html" mode="escaped">'.$title.'</title>'.
  '<dc:subject type="text/html" mode="escaped">'.$category.'</dc:subject>'.
  '<content type="application/xhtml+xml" mode="base64">'.$text64.'</content>'.
  '</entry>';

$headers = array(
              "X-WSSE" => $wsse,
              "Content-Type" => "application/x.atom+xml",
              "Cache-Control" => "no-cache",
              );

$curl = new Curl();
$curl->headers = $headers;
$curl->options = array("POSTFIELDS" => $rawdata);
$res = $curl->post($atomapi_url);
?>
    Υȥ꡼ϤƤʥ֥åޡɲ

TwitterAPI˸ɤꤲɽΥץ롣

ꥯȥѥ᡼ΰ㡣
ܺ٤Ϥ򻲾
q
callbackХåؿꤷȤ
langоݤθ
rpp븡̿
pageڡ


쥹ݥ󥹥ǡϤʤ󤸡
created_atȯ
from_user桼ID
profile_image_url桼Υץե
textȯ

³ƥȥץ롣
³ɤ
    Υȥ꡼ϤƤʥ֥åޡɲ

5ގَ
äAmazon᡼ƤΤбƤߤޤ
꤮ˤʤʤȤʤ
Ƶ٤ߤνȤäǤ

Ȥ櫓ǺޤϤƤparamȥåȥϤ
URL֤Ƥؿ

˼ʬѡ
֤ͤϤѤȤ͡

function amazonSignature ($param=array(), $secretKey="") {
  $aws = array("host" => "webservices.amazon.co.jp", "path" => "/onca/xml");
  ksort($param);

  $reqParam = array();
  foreach ($param as $key => $val) {
    $reqParam[] = $key . "=" . rawurlencode($val);
  }

  $paramStr = implode("&", $reqParam);
  $str = implode("\n", array('GET', $aws["host"], $aws["path"], $paramStr));
  $sig = rawurlencode( base64_encode( hash_hmac("sha256", $str, $secretKey, true)));
  $reqParam[] = "Signature=" . $sig;
  $url = "http://" . $aws["host"]. $aws["path"] . "?" . implode("&", $reqParam);

  return $url;
}

ʤߤparamˤϤʴΥǡ
ˤ碌ѹ
$param = array(
               "Service" => "AWSECommerceService",
               "AWSAccessKeyId" => "YOUR ACCESS KEY",
               "Operation" => "ItemSearch",
               "SearchIndex" => "Books",
               "ResponseGroup" => "Medium,Tracks",
               "BrowseNode" => "465610",
               "Timestamp" => gmdate("Y-m-d\TH:i:s\Z"),
               );
    Υȥ꡼ϤƤʥ֥åޡɲ

ȤǥԥڤǻȤ褦˥⡣

ܸʸϤȥե졼ФƤ롣
ʡοǿ礭ۤɽ٤⤤
appid
쥹ݥ󥹷jsonxmlphp serializeǽ
*)jQueryѡ


ɤϰʲ
$(function(){
  $("#postSentence").submit(function() {
    $("#postResult").empty();
    search($("#sentence").val());
    return false;
  });
  function search(text) {
    $("#postResult").text("Now Loading....");
    $.ajax({
      dataType: "jsonp",
      data: {
        "appid":"your appid",
        "sentence":text,
        "output":"json",
        "max-result":10,
      },
      cache: true,
      url: "http://jlp.yahooapis.jp/KeyphraseService/V1/extract",
      success: function(data) {
        var ul = $(document.createElement("ul"));
        ul.addClass("class20090807");
        $.each(data, function(word, score) {
          ul.append($(document.createElement("li"))
          .append(word)
          .append(' ('+score+')'));
        });
        $("#postResult").html(ul);
      }
    });
  }
});
    Υȥ꡼ϤƤʥ֥åޡɲ

ΥڡΥȥåץ