Google+ APIï½·ï¾ââââ(ï¾âï¾)ââââッ!!
ãã£ã¨ã§ã¾ãããGoogle+ APIï¼ããã§ä»åã®GDDãããããããªãããï¼
APIã使ç¨ãã¦ã§ãããã¨ã¯ã¾ã æ å ±ã®åå¾ã ãã ãã©ã大ä½ã©ããªæãã®APIã«ãªããã¯æ³åã§ããããJava、PHP、Python、Rubyのライブラリが既に存在するã®ãç´ æ´ããããï¼æ¬é³ãè¨ãã°Rubyçãªããã¯èªåã§ä½ã£ã¦ã¿ããã£ãæ°ããããã©ã»ã»ã»ï¼
ã¨ããããããã¥ã¡ã³ãã®ããããã¼ã¸ã訳ãã¦ã¿ã¾ããã
http://developers.google.com/+/api/
Google+ API
Goolge+ APIã¯Google+ã®ããã®ããã°ã©ãã³ã°ã¤ã³ã¿ã¼ãã§ã¼ã¹ã§ãããã®APIãå©ç¨ããã¨ã¢ããªã±ã¼ã·ã§ã³ãã¦ã§ããµã¤ããGoogle+ã¨çµ±åã§ãã¾ããããã«ãã£ã¦ã¦ã¼ã¶ã¼ã¯ããªãã®ã¢ããªã±ã¼ã·ã§ã³å ã§Google+ã®æ©è½ãæ大éã«å©ç¨ãã¦ç¸äºã«ç¹ãããã¨ãã§ãã¾ãã
注: Google+ APIã¯ç¾å¨ã®ã¨ããå ¬éãã¼ã¿ã¸ã®èªã¿è¾¼ã¿å°ç¨ã¢ã¯ã»ã¹ããæä¾ãã¦ãã¾ããããã¹ã¦ã®APIå¼ã³åºãã«OAuth2.0トークンãAPIキーãå¿ è¦ã§ãã
ã¯ã©ã¼ã¿
ã¢ã¦ãªã±ã¼ã·ã§ã³ã¯åªå¾ å©ç¨ã¯ã©ã¼ã¿ã«ãã£ã¦å¶éããã¦ãã¾ããããã¯APIããã¬ãã¥ã¼ãã¦ã¢ããªã±ã¼ã·ã§ã³ãã©ã®ããã«æ§ç¯ãããããèãå§ããã®ã«ååãªã¢ã¯ã»ã¹ãæä¾ãã¦ããã¯ãã§ããåªå¾ å¶éã¨ã¢ããªã±ã¼ã·ã§ã³ã®ãªã¯ã¨ã¹ãã®ä¸éã«ã¤ãã¦ã¯Google APIã®ã³ã³ã½ã¼ã«ãåç §ãã¦ãã ããã詳細ã«ã¤ãã¦ã¯Google APIコンソールヘルプãåç §ãã¦ãã ããã
èªå¯
å¤ãã®APIå¼ã³åºãã¯ãããªãã®ã¢ããªã±ã¼ã·ã§ã³ã®ã¦ã¼ã¶ã¼ã«ãã£ã¦å½¼ãã®ãã¼ã¿ã«ã¢ã¯ã»ã¹ãã許å¯ãä¸ãã¦ãããå¿ è¦ãããã¾ããGoogleã¯OAuth2.0ãããã³ã«ã使ç¨ãã¦ã¢ããªã±ã¼ã·ã§ã³ã«ã¦ã¼ã¶ã¼ãã¼ã¿ã«ã¢ã¯ã»ã¹ãã許å¯ãä¸ãããã¨ãã§ãã¾ãã詳細ã«ã¤ãã¦ã¯OAuthãåç §ãã¦ä¸ããã
APIå¼ã³åºã
ã»ã¨ãã©ã®Google+ APIã¯RESTful APIãã¶ã¤ã³ã«å¾ã£ã¦ãã¾ããã¤ã¾ããæ¨æºçãªHTTPã¡ã½ããã使ã£ã¦ãªã½ã¼ã¹ãåãåºããããæä½ãããã§ãã¾ããä¾ãã°ãã¦ã¼ã¶ã¼ã®ãããã£ã¼ã«ãåãåºãã«ã¯ã次ã®ãããªHTTPãªã¯ã¨ã¹ããéãã¨ããã§ããã:
å ±éã®ãã©ã¡ã¼ã¿
ç°ãªãAPIã¡ã½ããã¯URLãã¹ã®ä¸é¨ã¾ãã¯ã¯ã¨ãªãã©ã¡ã¼ã¿ã¨ãã¦ãã©ã¡ã¼ã¿ãè¦æ±ãã¾ããããã«ãããã¤ãã®ãã©ã¡ã¼ã¿ã¯å ¨ã¦ã®APIã¨ã³ããã¤ã³ãã§å ±éã§ãããããã¯å ¨ã¦ãªãã·ã§ãã«ãªã¯ã¨ãªãã©ã¡ã¼ã¿ã¨ãã¦æ¸¡ããã¨ãã§ãã¾ãã
ãã©ã¡ã¼ã¿å | å¤ | 説æ | |
---|---|---|---|
callback | æåå | JSONPã§APIãå©ç¨ããããã«ã¬ã¹ãã³ã¹ãã¼ã¿ã渡ãããã®JavaScripté¢æ°ãæå® | |
fields | æåå | 部分レスポンスã«ã©ã®ãã£ã¼ã«ããå«ãããæå®ããããã®ã»ã¬ã¯ã¿ | |
key | æåå | APIãã¼ãAPIãã¼ã¯ããã¸ã§ã¯ããèå¥ããAPIã¸ã®ã¢ã¯ã»ã¹ã¨ã¯ã©ã¼ã¿ãã¬ãã¼ããæä¾ãã¾ããOAuth 2.0ãã¼ã¯ã³ããªããã°å¿ é ã | |
access_token | æåå | ç¾å¨ã®ã¦ã¼ã¶ã¼ã®ããã®OAuth 2.0ãã¼ã¯ã³ã詳細ã«ã¤ãã¦ã¯ OAuth. | |
prettyPrint | çå½å¤ | ãã"true"ã«è¨å®ããã¦ããã°ãèªã¿ãããããããã«ãã¼ã¿ã®åºåã«æ¹è¡ã¨ã¤ã³ãã³ããå«ã¾ãã¾ãã"false"ã®è¨å®ããã¦ããã°ãä¸è¦ãªãã¯ã¤ãã¹ãã¼ã¹ã¯åé¤ãããã¬ã¹ãã³ã¹ã®ãµã¤ãºãç¯ç´ãã¾ããããã©ã«ãã¯"true"ã | |
userIp | æåå | APIå¼ã³åºããä½æããã¦ã¼ã¶ã¼ã®IPã¢ãã¬ã¹ãèå¥ãã¾ããããã«ãã£ã¦ãµã¼ãã¼ãµã¤ãã¢ããªã±ã¼ã·ã§ã³ããã®APIå¼ã³åºãã§ãã¦ã¼ã¶ã¼åä½ã§ã®ã¯ã©ã¼ã¿ãå¼·å¶ããã¾ãã詳細ã«ã¤ãã¦ã¯ Capping Usageã |
ãã¼ã¿å½¢å¼
Google+ APIã§ã¯ãªã½ã¼ã¹ã¯JSONãã¼ã¿å½¢å¼ã§è¡¨ããã¾ããä¾ãã°ãã¦ã¼ã¶ã¼ã®ãããã£ã¼ã«ãåå¾ããã¨ã¬ã¹ãã³ã¹ã¯æ¬¡ã®ããã«ãªãã§ããã:
{ "kind": "plus#person", "id": "118051310819094153327", "displayName": "Chirag Shah", "url": "https://plus.google.com/118051310819094153327", "image": { "url": "https://lh5.googleusercontent.com/-XnZDEoiF09Y/AAAAAAAAAAI/AAAAAAAAYCI/7fow4a2UTMU/photo.jpg" } }
å ±éã®ããããã£
ãã¾ãã¾ãªã¿ã¤ãã®ãªã½ã¼ã¹ãããããç¬èªã®å½¢å¼ãæã£ã¦ãã¾ãããã»ã¨ãã©ãã¹ã¦ã®ãªã½ã¼ã¹ã«è¦ãããå ±éã®ããããã£ãããããããã¾ãã
ããããã£å | å¤ | 説æ |
---|---|---|
displayName | æåå | ã¦ã¼ã¶ã¼ã®ããã«è¡¨ç¤ºããã®ã«é©ãããªã½ã¼ã¹ã®ååã§ãã |
id | æåå | ãªã½ã¼ã¹ãä¸æã«èå¥ããããã®ããããã£ã§ããä¸ãããã種é¡ï¼kindï¼ã®å ¨ãªã½ã¼ã¹ã¯ã¦ãã¼ã¯IDãæã¡ã¾ããidãæ°å¤ã®ããã«è¦ããã¨ãã¦ãã常ã«æååã¨ãã¦æ±ããã¾ãã |
kind | æåå | JSONãªãã¸ã§ã¯ã表ç¾ã®ãªã½ã¼ã¹ç¨®å¥ãèå¥ãã¾ããæªç¥ã®ãªãã¸ã§ã¯ããããã°ã©ã çã«ã©ã®ããã«ãã¼ã¹ãããã決å®ããå ´åã«ç¹ã«æç¨ã§ãã |
url | æåå | ãªã½ã¼ã¹ã®ä¸»URLã¾ãã¯ãã¼ããªã³ã¯ã§ãã |
ãã¼ã¸ãã¼ã·ã§ã³
ä¾ãã°ã¢ã¯ãã£ããã£ãªã¹ãã®ãããªã巨大ãªéåãè¿ãå¯è½æ§ããããªã¯ã¨ã¹ãã§ã¯ãmaxResultsï¼ããã©ã«ãå¤:20ï¼ãè¨å®ãã¦ã¬ã¹ãã³ã¹ã«å«ã¾ããã¢ã¤ãã æ°ãå¶éã§ãã¾ããããããã®ã¬ã¹ãã³ã¹ã¯ã¾ãnextPageTokenããããã£ãè¿ãã¾ãã次ã®ãã¼ã¸ã®ã¢ã¤ãã ãåå¾ããã«ã¯ã次ã®ãªã¯ã¨ã¹ãã®pageTokenããããã£ã«ãã®nextPageTokeã®å¤ãä¸ããªããã°ããã¾ããããã®æé ãç¹°ãè¿ããã¨ã§å ¨ã¦ã®éåãæã«å ¥ãããã¨ãã§ãã¾ãã
ä¾ãã°ãã¢ã¯ãã£ããã£ãªã¹ãå¼ã³åºãã¯nextPageTokenãå«ã次ã®ãããªã¬ã¹ãã³ã¹ãè¿ãã¾ã:
{ "kind": "plus#activityFeed", "title": "Plus Public Activities Feed", "nextPageToken": "CKaEL", "items": [ { "kind": "plus#activity", "id": "123456789", ... }, ... ] ... }
次ã®ãã¼ã¸ã®ã¢ã¯ãã£ããã£ãåå¾ããã«ã¯ã次ã®ã¢ã¯ãã£ããã£ãªã¹ããªã¯ã¨ã¹ãã«ãã®ãã¼ã¯ã³ã®å¤ã渡ãã¾ã:
https://www.googleapis.com/plus/v1/people/me/activities/public?pageToken=CKaEL
å ã¨åæ§ããã®ãªã¯ã¨ã¹ãã®ã¬ã¹ãã³ã¹ã«ãnextPageTokenãå«ã¾ããããã«æ¬¡ã®ãã¼ã¸ã®çµæãå¾ãããã«ä½¿ç¨ã§ãã¾ããæ°ãããã¼ã¸ãå¾ãã«ã¯ãã®ãµã¤ã¯ã«ãç¹°ãè¿ãã¾ããæå¾ã®ãã¼ã¸ã§ã¯"nextPageToken"ã¯ç©ºç½ã«ãªãã¾ãã
é¨åã¬ã¹ãã³ã¹
ããã©ã«ãã§ã¯ããªã¯ã¨ã¹ãå¦çã®å¾ã«ãªã½ã¼ã¹ã®å®å ¨ãªå½¢å¼ãéãè¿ãã¾ããããã©ã¼ãã³ã¹ãåä¸ãããããããµã¼ãã¼ã«æ¬å½ã«å¿ è¦ãªãã£ã¼ã«ãã ããéãè¿ãããã«ä¾é ¼ãã¦ãé¨åçãªã¬ã¹ãã³ã¹ã代ããã«åãåããã¨ãã§ãã¾ãã
é¨åã¬ã¹ãã³ã¹ããªã¯ã¨ã¹ãããã«ã¯ãfieldsãªã¯ã¨ã¹ããã©ã¡ã¼ã¿ã使ç¨ãã¦è¿ãã¦æ¬²ãããã£ã¼ã«ããæå®ãã¾ãããã®ãã©ã¡ã¼ã¿ã¯ã¬ã¹ãã³ã¹ããã£ãè¿ããã¹ã¦ã®ãªã¯ã¨ã¹ãã§ä½¿ç¨ã§ãã¾ãã
ä¾
次ã®ä¾ã§Google+ APIã®fieldsãã©ã¡ã¼ã¿ãã©ãå©ç¨ããããåããã¾ãã
åç´ãªãªã¯ã¨ã¹ã: ãã®HTTP GETãªã¯ã¨ã¹ãã¯fieldsãã©ã¡ã¼ã¿ããªãä½åãã®ãã£ã¼ã«ããå«ãå ¨アクティビティリソースãè¿ãã¾ãã
https://www.googleapis.com/plus/v1/activities/z12gtjhq3qn2xxl2o224exwiqruvtda0i?key=YOUR-API-KEY
é¨åã¬ã¹ãã³ã¹ãªã¯ã¨ã¹ã: ãã®HTTP GETãªã¯ã¨ã¹ãã¯ä¸è¨ã®ãªã½ã¼ã¹ãè¿ãã¾ãããfieldsãã©ã¡ã¼ã¿ã使ç¨ãã¦ãã¦ãè¿ããããã¼ã¿ã®éãå¤§å¹ ã«åæ¸ãã¦ãã¾ãã
ä¸ã®ãªã¯ã¨ã¹ãã®ã¬ã¹ãã³ã¹ã¨ãã¦ããµã¼ãã¼ã¯urlãã£ã¼ã«ãã¨ãcontentã¨attachments.urlã ããå«ã軽éãªobjectã ããå«ãJSONå½¢å¼ãè¿ãã¾ãã
{ "url": "https://plus.google.com/102817283354809142195/posts/F97fqZwJESL", "object": { "content": "A picture... of a space ship... launched from earth 40 years ago.", "attachments": [ { "url": "http://apod.nasa.gov/apod/ap110908.html" } ] } }
ã¬ã¹ãã³ã¹ã¯é¸æããããã£ã¼ã«ãã¨ãããå ã親ãªãã¸ã§ã¯ãã ããå«ãJSONãªãã¸ã§ã¯ãã«ãªããã¨ã«æ³¨æãã¦ä¸ããã
fieldsãã©ã¡ã¼ã¿ã®ã·ã³ã¿ãã¯ã¹ã¯æ¬¡ã§èª¬æãã¾ããã¬ã¹ãã³ã¹ã«ä½ãè¿ããããã«ã¤ãã¦ã®è©³ç´°ã¯ããã«ãã®å¾ã«ããã¾ãã
fieldsãã©ã¡ã¼ã¿ã®ã·ã³ã¿ãã¯ã¹ã¾ã¨ã
fieldsãªã¯ã¨ã¹ããã©ã¡ã¼ã¿ã®å¤ã®å½¢å¼ã¯å¤§éæã«XPathã·ã³ã¿ãã¯ã¹ã«åºã¥ãã¦ãã¾ãããµãã¼ããããã·ã³ã¿ãã¯ã¹ãä¸ã«ã¾ã¨ããç¶ãç¯ã§è¿½å ã®ä¾ãç´¹ä»ãã¾ãã
- ã«ã³ãã§åå²ããããªã¹ãã¯è¤æ°ã®ãã£ã¼ã«ããé¸æããããã«ä½¿ç¨ãã¾ãã
- a/bã¯ãã£ã¼ã«ãaã«ãã¹ãããããã£ã¼ã«ãbãé¸æããããã«ä½¿ç¨ãã¾ããbã«ããã«å«ã¾ãããã£ã¼ã«ãcãé¸ã¶ã«ã¯a/b/cã使ç¨ãã¦ä¸ããã
- ç¹å®ã®ãµããã£ã¼ã«ãã ããè¦æ±ãããã£ã¼ã«ããµãã»ã¬ã¯ã¿ã¯ä»»æã®é¸æããããã£ã¼ã«ãã®å¾ã«æ¬å¼§"( )"ã追å ãã¦æå®ã§ãã¾ãã
ä¾ãã°: fields=items(id,object/content)ã¯itemsé åè¦ç´ ã®ããããã«ã¤ãã¦ã¢ã¤ãã idã¨objectã®contentã ããè¿ãã¾ãã - å¿
è¦ã§ããã°ãã£ã¼ã«ãã®é¸æã«ã¯ã¤ã«ãã«ã¼ãã使ç¨ã§ãã¾ãã
ä¾ãã°: fields=items/object/* ã¯objectã®ä¸ã®ãã¹ã¦ã®ã¢ã¤ãã ãé¸æãã¾ãã
ããã«fieldsãã©ã¡ã¼ã¿ã使ç¨ããä¾
次ã®ä¾ã¯fieldsãã©ã¡ã¼ã¿ã®å¤ãã©ã®ããã«ã¬ã¹ãã³ã¹ã«å½±é¿ãä¸ãããã®èª¬æãå«ã¿ã¾ãã
注: ãã¹ã¦ã®ã¯ã¨ãªãã©ã¡ã¼ã¿ã®å¤ã¨åæ§ã«ãfieldsãã©ã¡ã¼ã¿ãURLã¨ã³ã³ã¼ãããã¦ããªããã°ããã¾ãããèªã¿ãããã®ããã«ããã®ããã¥ã¡ã³ãã®ä¾ã§ã¯ã¨ã³ã³ã¼ãã£ã³ã°ãçç¥ãã¦ãã¾ãã
ãã£ã¼ã«ãé¸æ: è¿ãã¦æ¬²ãããã£ã¼ã«ããæå®ã
fieldsãªã¯ã¨ã¹ããã©ã¡ã¼ã¿ã®å¤ã¯ãã£ã¼ã«ãã®ã«ã³ãåå²ããããªã¹ãã§ãããããã®ãã£ã¼ã«ãã¯ã¬ã¹ãã³ã¹ã®ã«ã¼ãããã®ç¸å¯¾ä½ç½®ã§æå®ããã¾ããå¾ã£ã¦ããããªã¹ããªãã¬ã¼ã·ã§ã³ãå®è¡ãã¦ãããªãã¬ã¹ãã³ã¹ã¯éåã§ä¸è¬çã«ã¯ãªã½ã¼ã¹ã®é åãå«ã¿ã¾ããããåä¸ã®ãªã½ã¼ã¹ãè¿ãæä½ãå®è¡ãã¦ãããªããã£ã¼ã«ãã¯ãªã½ã¼ã¹ã®ç¸å¯¾ä½ç½®ã§æå®ããªããã°ããã¾ãããããããªããé¸æãããã£ã¼ã«ãï¼ãããããã¯ãã®ä¸é¨ï¼ãé åãªãããµã¼ãã¼ã¯é åã®å ¨è¦ç´ ã®é¸æãããé¨åãè¿ãã¾ãã
以ä¸ã¯activities.listããåã£ãããã¤ãã®éåã¬ãã«ã®ä¾ã§ã:
ä¾ | å¹æ |
---|---|
items | itemsé åã«å«ã¾ããå ¨ã¦ã®è¦ç´ ã¨ããããã®è¦ç´ ã«å«ã¾ããå ¨ã¦ã®ãã£ã¼ã«ããè¿ãã¾ããããã®ä»ã®ãã£ã¼ã«ãã¯è¿ãã¾ããã |
updated,items | updatedãã£ã¼ã«ãã¨ãitemsé åã®å ¨è¦ç´ ãè¿ãã¾ãã |
items/title | itemsé
åã®å
¨è¦ç´ ã®titleãã£ã¼ã«ãã ããè¿ãã¾ãã Whenever a nested field is returned, the response includes the enclosing parent objects. The parent fields do not include any other child fields unless they are also selected explicitly. |
以ä¸ã¯activitiesããåã£ãããã¤ãã®ãªã½ã¼ã¹ã¬ãã«ã®ä¾ã§ã:
ä¾ | å¹æ |
---|---|
title | ãªã¯ã¨ã¹ãããããªã½ã¼ã¹ã®titleãã£ã¼ã«ããè¿ãã¾ãã |
actor/displayName | ãªã¯ã¨ã¹ãããããªã½ã¼ã¹ã®actorãªãã¸ã§ã¯ãã®displayNameãµããã£ã¼ã«ããè¿ãã¾ãã |
object/attachments/url | objectãªãã¸ã§ã¯ãã«ãã¹ããããattachmentsé åã®å ¨ã¡ã³ãã¼ã®urlãã£ã¼ã«ãã ããè¿ãã¾ãã |
ãã£ã¼ã«ããµãé¸æ: é¸æãããè¦ç´ ã®ä¸é¨åãè¦æ±ã
ããã©ã«ãã§ã¯ãç¹å®ã®ãªãã¸ã§ã¯ããæå®ããã¨ããµã¼ãã¼ã¯ãªãã¸ã§ã¯ãã丸ãã¨è¿ãã¾ããé¸æããããªãã¸ã§ã¯ãã®ãããµããã£ã¼ã«ãã ããå«ããããªã¬ã¹ãã³ã¹ãè¦æ±ãããã¨ãã§ãã¾ããããã«ã¯æ¬¡ã®ä¾ã®ããã« "( )" ãµãé¸æã·ã³ã¿ãã¯ã¹ã使ç¨ãã¦ä¸ããã
ä¾ | å¹æ |
---|---|
items(id,url) | itemsé åã«å«ã¾ããããããã®è¦ç´ ã«ã¤ãã¦idã¨urlãã£ã¼ã«ãã®å¤ã ããè¿ãã¾ãã |
é¨åã¬ã¹ãã³ã¹ãæ±ã
ãµã¼ãã¼ã¯fieldsã¯ã¨ãªãã©ã¡ã¼ã¿ãå«ã妥å½ãªãªã¯ã¨ã¹ããå¦çããå¾ã§ãè¦æ±ããããã¼ã¿ã¨å ±ã«HTTP 200 OKã¹ãã¼ã¿ã¹ã³ã¼ããéãè¿ãã¾ããfieldsã¯ã¨ãªãã©ã¡ã¼ã¿ãã¨ã©ã¼ãçºçããããä¸å½ãªå ´åã«ã¯ããµã¼ãã¼ã¯fieldsé¸æã®ä½ãééã£ã¦ããããä¼ããã¨ã©ã¼ã¡ãã»ã¼ã¸ï¼ä¾ãã°ã"Invalid field selection a/b"ï¼ã¨å ±ã«HTTP 400 Bad Requestã¹ãã¼ã¿ã¹ã³ã¼ããè¿ãã¾ãã
注: å¯è½ãªå ´åã¯ãã¤ã§ããããããã®ã¯ã¨ãªã®çµæã管çã§ãããµã¤ãºã«æããããããã«maxResultsã使ç¨ãã¾ããããããããªããã°ãé¨åã¬ã¹ãã³ã¹ã«ãã£ã¦å¾ãããããã©ã¼ãã³ã¹ã¯å®æã§ããªãã§ãããã