Web APIs

★Web APIs分類(実装タイプにより)

1.URLだけを記述するタイプ

サンプル

<img src="http://capture.heartrails.com/400x400/shadow?sites.google.com/site/webdevelopart/" />

<img src="http://img.simpleapi.net/small/http://www.google.co.jp" />

<img src="http://map.olp.yahooapis.jp/OpenLocalPlatform/V1/static?appid=アプリケーションID&lat=緯度&lon=経度&z=15&width=300&height=400&pointer=on" />

※APIの戻り値は主に画像など

2.JavaScriptを取り込むタイプ

サンプル1

<script type="text/javascript" src="http://www.google.com/jsapi?key=取得したAPIキー"></script>

<script type="text/javascript">

google.load("feeds", "1");

google.setOnLoadCallback(init);

function init(){

var feed = new google.feeds.Feed("http://b.hatena.ne.jp/t/google?mode=rss&sort=hot&threshold=8");

feed.setNumEntries(10);

...

}

</script>

サンプル2

<script type="text/javascript" src="http://js.api.olp.yahooapis.jp/OpenLocalPlatform/V1/jsapi?appid=アプリケーションID"></script>

<script type="text/javascript">

window.onload = function(){

var ymap = new Y.Map("map");

ymap.drawMap(new Y.LatLng(緯度, 経度), 15, Y.LayerSetId.NORMAL);

}

</script>

<div id="map" style="width:300px;height=400px" />

※APIの戻り値は主にRSSやAtom

3.Webサービスタイプ

サンプル

http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=取得したAPIキー&text=キーワード(URLエンコード済)&sort=interestingness-desc&per_page=件数

http://api.rakuten.co.jp/rws/3.0/rest?developerId=デベロッパーID&affiliateId=アフィリエイトID&operation=ItemSearch&version=2012-XX-XX&keyword=キーワード(URLエンコード済)&hits=件数&sort=standard

※APIの戻り値は主にXMLやJSONなので、ほとんどサーバサイドで情報を組み立てる

4.JSONPタイプ

JSONP:クロス・ドメインのJSONデータを非同期で読み込んで処理する仕組み

サンプル1

<script type="text/javascript"

src="http://api.rakuten.co.jp/rws/3.0/json?developerId=デベロッパーID&affiliateId=アフィリエイトID&operation=ItemSearch&version=2012-XX-XX&keyword=キーワード(URLエンコード済)&hits=件数&sort=standard&callBack=callbackFunc" ></script>

<script type="text/javascript">

function callbackFunc(items){

var num = items.Body.ItemSearch.Items.Item;

for(var i in num){

...

}

}

</script>

サンプル2

<script type="text/javascript"

src="http://search.twitter.com/search.json?callbackFunc&lang=ja&locale=ja&q=検索クエリ" ></script>

<script type="text/javascript">

function callbackFunc(data){

for(var i in data.results){

...

}

}

</script>

※APIの戻り値は

関数名({

JSONデータ

});

★Web APIs分類(機能により)

・フィード

Google AJAX Feed API http://code.google.com/intl/ja/apis/ajaxfeeds/

・動画

YouTube

Ustream

・写真

Flickr http://www.flickr.com/services/api/

・アフィリエイト

楽天ウェブサービス http://webservice.rakuten.co.jp/

Amazon Product Advertising API https://affiliate.amazon.co.jp/

・Map

Google Maps API http://code.google.com/intl/ja/apis/maps/

Yahoo! Open Local Platform http://developer.yahoo.co.jp/webapi/map/

・SNS

Twitter API http://apiwiki.twitter.com/

Search API Methods

REST API Methods

Facebook API

Mixi API

・グラフ

JSChart http://www.jschart.jp/products/api.php

Google Chart API

・サムネイル

HeartRails Capture http://capture.heartrails.com/

SimpleAPI http://img.simpleapi.net/

・最寄り駅

SimpleAPI http://map.simpleapi.net/

・Wikipedia

SimpleAPI http://wikipedia.simpleapi.net/

・テキスト

Yahoo!デベロッパーネットワーク

テキスト解析ルビ振り API http://developer.yahoo.co.jp/webapi/jlp/furigana/v1/furigana.html

かな漢字変換 API http://developer.yahoo.co.jp/webapi/jlp/jim/v1/conversion.html

コンテンツマッチアイテム API

http://developer.yahoo.co.jp/webapi/auctions/auction/v1/contentsmatchitem.html

間違い.net API http://www.machigai.net/

・テレビ

日テレアプリ http://www.ntv.co.jp/appli/api/

・Google URL shortenerサービス

http://goo.gl/

★Google API関連

APIアクセス設定 https://code.google.com/apis/console/

API使用ガイド http://code.google.com/p/google-api-java-client/wiki/APIs

>Gmail

https://mail.google.com/mail/?

view=cm&

tf=1&

fs=1&

su=XXX&

to=a@gmail.com&

cc=b@gmail.com&

bcc=c@gmail.com&

body=XXX

%0d%0a 改行

%20 半角スペース

%3f ? マーク

>Calendar

https://www.google.com/calendar/feeds/someone@gmail.com/private/full

https://www.google.com/calendar/feeds/default/private/full

>Document

http://docs.google.com/feeds/default/private/full

★API testing

https://www.runscope.com/

http://requestb.in/

★Versionの設計

方法1:URL

/api/v2/foo

方法2:custom request header

/api/foo

api-version: 2

方法3:content type

/api/foo

Accept: application/vnd.example.v2+json

或いは

Accept: application/vnd.example+json; version=2.0

方法4:parameter

/api/foo?v=2