Google+ APIが公開されたので試してみた
Google+ API が公開された。まだ参照系のAPI( People.get Activities.get Activities.list )のみだけど、これからどんどん楽しくなるといいな。
- Google+ API - Google+ Platform ― Google Developers
- Getting Started on the Google+ API - Google+ Platform Blog
APIs Explorer(APIを簡単に試せるところ)には Google+ API があったけど、 Activities.list はうまく動かなかった。People.get と Activities.get は動いた。
Google APIs Explorer
またAPIのドキュメントの examples の URL も間違っていて、うまく動かなかった。残念。でもURLはちょこっと直せばちゃんと動いた。
Google+ API の使い方
大して難しくないけど、Simple API Access の使い方を書いておく。今回は取り上げないけど、Google+ API はOAuth2にも対応している。
いまは APIのリクエスト数の制限が 1,000 queries/day なので、ご利用は計画的に。
プロフィールの取得 / people.get
リファレンスはこちら。
こんな感じで id を指定するだけ。idはプロフィール画面のURLにある数字のやつ。僕の id は 107682764353690170518 になる。yourAPIKey には、さっき取得した API Key を入れる。
https://www.googleapis.com/plus/v1/people/107682764353690170518?key=
このURLにアクセスすると、こんな感じの情報が取得できる。(長いので整形している)
{ "kind": "plus#person", "id": "107682764353690170518", "displayName": "sada h", "gender": "male", "aboutMe": "<div>すきなこと寝ること。きらいなこと起きること。 </div><div>Javaすき。システムエンジニア。</div><div>写真すき。一眼レフ、明るい単焦点レンズすき。</div><div>鎌倉すき。鎌倉在住。</div><div>お酒すき。ワイン、ウィスキー。</div><div><br></div><div>----</div><div><div>Zen-Coding 使ってます。</div></div><div><br></div><div>Zen-Coding の Chrome Extension 作ってます。</div><div><a href=\"https://chrome.google.com/webstore/detail/iodhcpffklplnfaihoolhfbejbinhcgn\">https://chrome.google.com/<WBR>webstore/detail/<WBR>iodhcpffklplnfaihoolhfbejbinhc<WBR>gn</a></div><div><br></div><div>UserScriptも作ってます。</div><div><a href=\"http://userscripts.org/scripts/show/105015\">http://userscripts.org/<WBR>scripts/show/105015</a></div><div><br></div><div>@ITで記事を書きました。</div><div>もしも10分の1の行数でHTMLが書けたら(1/2) ─ @IT</div><div><a href=\"http://www.atmarkit.co.jp/fwcr/design/tool/zencoding01/01.html\">http://www.atmarkit.co.jp/<WBR>fwcr/design/tool/zencoding01/<WBR>01.html</a></div><div><br></div><div><br></div>", "url": "https://plus.google.com/107682764353690170518", "image": { "url": "https://lh5.googleusercontent.com/-E1jvr_nZ6mY/AAAAAAAAAAI/AAAAAAAAAfw/IYToOPlWagA/photo.jpg" }, "urls": [ { "value": "http://d.hatena.ne.jp/j7400157/" }, { "value": "http://twitter.com/sada_h" }, ], "placesLived": [ { "value": "鎌倉" } ] }
アクティビティの一覧の取得 / activities.list
リファレンスはこちら。
こっちも id を指定するだけ。yourAPIKey には、さっき取得した API Key を入れる。
https://www.googleapis.com/plus/v1/people/107682764353690170518/activities/public?key=
このURLにアクセスすると、こんな感じの情報が取得できる。(長いので整形している)
{ "kind": "plus#activityFeed", "nextPageToken": "eJx9UzFIw0AU_ ...", "selfLink": "https://www.googleapis.com/plus/v1/people/107682764353690170518/activities/public?", "nextLink": "https://www.googleapis.com/plus/v1/people/107682764353690170518/activities/public?maxResults=...", "title": "Plus Public Activity Feed for sada h", "updated": "2011-09-16T04:43:17.752Z", "id": "tag:google.com,2010:/plus/people/107682764353690170518/activities/public", "items": [ { "kind": "plus#activity", "title": "今日はGoogle+ API祭りだね!! http://googlecode.blogspot.com/2011/09/getting-started-on-google-api.html ht...", "published": "2011-09-16T00:58:33.000Z", "updated": "2011-09-16T00:58:34.466Z", "id": "z13bfr2pwv3tw1d1d23kjbpzwoy4uxai204", "url": "https://plus.google.com/107682764353690170518/posts/7uX4T3w7pow", "actor": { "id": "107682764353690170518", "displayName": "sada h", "url": "https://plus.google.com/107682764353690170518", "image": { "url": "https://lh5.googleusercontent.com/-E1jvr_nZ6mY/AAAAAAAAAAI/AAAAAAAAAAA/V0zxFDohKp8/photo.jpg" } }, "verb": "post", "object": { "objectType": "note", "content": "今日はGoogle+ API祭りだね!!<br /><a href=\"http://googlecode.blogspot.com/2011/09/getting-started-on-google-api.html\" >http://googlecode.blogspot.com/2011/09/getting-started-on-google-api.html</a><br /><a href=\"http://d.hatena.ne.jp/technohippy/20110916#1316131817\" >http://d.hatena.ne.jp/technohippy/20110916#1316131817</a><br /><a href=\"https://groups.google.com/group/google-social-developers-japan/browse_thread/thread/ce6f266fb1a61994#\" >https://groups.google.com/group/google-social-developers-japan/browse_thread/thread/ce6f266fb1a61994#</a>", "url": "https://plus.google.com/107682764353690170518/posts/7uX4T3w7pow", "replies": { "totalItems": 0 }, "plusoners": { "totalItems": 2 }, "resharers": { "totalItems": 0 }, "attachments": [ { "objectType": "article", "displayName": "Getting started on the Google+ API - The official Google Code blog", "content": "Getting started on the Google+ API", "url": "http://googlecode.blogspot.com/2011/09/getting-started-on-google-api.html" }, { "objectType": "photo", "image": { "url": "http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=http%3A%2F%2F3.bp.blogspot.com%2F-JJJfH4o5F9c%2FTnJEHO9CZHI%2FAAAAAAAAAyM%2FFgOmjuAKc-A%2Fs1600%2Fresized%252Bheadshot.jpg", "type": "image/jpeg" }, "fullImage": { "url": "http://3.bp.blogspot.com/-JJJfH4o5F9c/TnJEHO9CZHI/AAAAAAAAAyM/FgOmjuAKc-A/s1600/resized%2Bheadshot.jpg", "type": "image/jpeg" } } ] }, "provider": { "title": "Google+" }, "access": { "kind": "plus#acl", "items": [ { "type": "public" } ] } }, ... ] }
アクティビティの取得 / activities.get
リファレンスはこちら。
最初これの使い方がわからなくて、ちょっと苦労した。こんな URL でアクセスするけど、ActivityID に何をいれればよいのかわからなかった。
いろいろ試してみると、さっき activities.list で取得した json で、items配列のオブジェクトに id があって、これをいれる。さっきの json だと、こんな値だった。activities.list 以外から id を取得する方法ってないのかな…。
"id": "z13bfr2pwv3tw1d1d23kjbpzwoy4uxai204",
これで ActivityIDもわかった。yourAPIKey には、さっき取得した API Key を入れる。
https://www.googleapis.com/plus/v1/activities/z13bfr2pwv3tw1d1d23kjbpzwoy4uxai204?key=yourAPIKey
このURLにアクセスすると、こんな感じの情報が取得できる。(長いので整形している)
{ "kind": "plus#activity", "title": "今日はGoogle+ API祭りだね!! http://googlecode.blogspot.com/2011/09/getting-started-on-google-api.html ht...", "published": "2011-09-16T00:58:33.000Z", "updated": "2011-09-16T00:58:34.466Z", "id": "z13bfr2pwv3tw1d1d23kjbpzwoy4uxai204", "url": "https://plus.google.com/107682764353690170518/posts/7uX4T3w7pow", "actor": { "id": "107682764353690170518", "displayName": "sada h", "url": "https://plus.google.com/107682764353690170518", "image": { "url": "https://lh5.googleusercontent.com/-E1jvr_nZ6mY/AAAAAAAAAAI/AAAAAAAAAAA/V0zxFDohKp8/photo.jpg" } }, "verb": "post", "object": { "objectType": "note", "content": "今日はGoogle+ API祭りだね!!<br /><a href=\"http://googlecode.blogspot.com/2011/09/getting-started-on-google-api.html\" >http://googlecode.blogspot.com/2011/09/getting-started-on-google-api.html</a><br /><a href=\"http://d.hatena.ne.jp/technohippy/20110916#1316131817\" >http://d.hatena.ne.jp/technohippy/20110916#1316131817</a><br /><a href=\"https://groups.google.com/group/google-social-developers-japan/browse_thread/thread/ce6f266fb1a61994#\" >https://groups.google.com/group/google-social-developers-japan/browse_thread/thread/ce6f266fb1a61994#</a>", "url": "https://plus.google.com/107682764353690170518/posts/7uX4T3w7pow", "replies": { "totalItems": 0 }, "plusoners": { "totalItems": 2 }, "resharers": { "totalItems": 0 }, "attachments": [ { "objectType": "article", "displayName": "Getting started on the Google+ API - The official Google Code blog", "content": "Getting started on the Google+ API", "url": "http://googlecode.blogspot.com/2011/09/getting-started-on-google-api.html" }, { "objectType": "photo", "image": { "url": "http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=http%3A%2F%2F3.bp.blogspot.com%2F-JJJfH4o5F9c%2FTnJEHO9CZHI%2FAAAAAAAAAyM%2FFgOmjuAKc-A%2Fs1600%2Fresized%252Bheadshot.jpg", "type": "image/jpeg" }, "fullImage": { "url": "http://3.bp.blogspot.com/-JJJfH4o5F9c/TnJEHO9CZHI/AAAAAAAAAyM/FgOmjuAKc-A/s1600/resized%2Bheadshot.jpg", "type": "image/jpeg" } } ] }, "provider": { "title": "Google+" }, "access": { "kind": "plus#acl", "items": [ { "type": "public" } ] } }
まとめ
API少ないし、参照系だけなので簡単だった。簡単なうちに勉強しておくと、あとあと楽になるかな。
本当は Client Library を使ったサンプルも載せようと思ったけど、だいぶ長くなったやめた。
.NET / GWT / Java / Objective-C / PHP / Python / Ruby のライブラリがすでに公開されている。beta や alpha だけど。
さらに Java / PHP / Python / Ruby についてはスターターキットとして、サンプルコードが公開されている。言語によって異なるけど、Webアプリケーションや、コマンドラインアプリーケーションのサンプルがある。
- google-plus-java-starter - A starting point for your awesome Google+ Applications - Google Project Hosting
- google-plus-php-starter - A starting point for your awesome Google+ PHP Applications - Google Project Hosting
- google-plus-python-starter - A starting point for your awesome Google+ Applications - Google Project Hosting
- google-plus-ruby-starter - A starting point for your awesome Google+ Applications - Google Project Hosting
Javaでは Command line / Google AppEngine / J2EE web application / Android のサンプルが公開されている。すごすぎ。
サンプルの充実度で、Googleの本気度もわかる気がした。