�ܻؤ�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�ǵ������������������η�̤���post����URL��ȤäƵ������ꤲ��ߤ�����

������Ѥ�����������
³�����ɤ�
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

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

���ܸ��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ʸ������ä��Τǡ�
���ܿͤ�30��40ʸ���ǤĤ֤䤤�Ƥ����Ǥ��礦�����֤�

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������ô���äݤ����ߤ����פ򥭡���ɤ˽���Ƥߤޤ�����

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


����˾�ʤ���

Íß˾¤Ê¤¦

����å�����ä��ꡢ�⤦����äȥꥢ�륿��������������Ȳ�������¿������Ȼפ��ΤǤܤ��ܤ����ޤ���
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

�����livedoorBlog��AtomAPI������˰���³������֥����ä��㤦�����Ȼפä���ϥޤä���
Ʊ��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�ѡ�
PHP��cURL���ѡ�

<?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ȯ��

³���ƥ������ȥ���ץ롣
³�����ɤ�
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ


����ε�����http://blog.livedoor.jp/j_yuze/archives/51369191.html�ˤ�����ơ� �����������ԥڤǻȤ���褦�ˤ��Ȥ����꡼����

�ޤ���youtubeAPI��

³�����ɤ�
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

����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������������������롣
�쥹�ݥ󥹷�����json��xml��php 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);
      }
    });
  }
});
    ¤³¤Î¥¨¥ó¥È¥ê¡¼¤ò¤Ï¤Æ¤Ê¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ËÄɲÃ

¤³¤Î¥Ú¡¼¥¸¤Î¥È¥Ã¥×¥Ø