Googleã«ã¬ã³ãã¼ã®ãã©ã¤ãã¼ãã¹ã±ã¸ã¥ã¼ã«ãJSONPã§é ä¿¡ãããµã¼ãã¹
ãGoogle Account Authentication APIを利用してGoogleカレンダーのフィードを取ってくるãã§ä½ã£ãã¢ããªãçºå±ããã¦ãã¦ã¼ã¶ã®ãã©ã¤ãã¼ãã¹ã±ã¸ã¥ã¼ã«ãã¼ã¿ãJSONPã§ãããã·é ä¿¡ãããµã¼ãã¹ãå®é¨çã«å®è£ ãã¦ã¿ãã
ããã¯ä»¥åパーソナルデータのマッシュアップã®æ§æ³ã§è¨ã£ã¦ããä»çµã¿ããå®éã«å®è£ ãããã®ã
JSONPã®å¼ã³åºãURLã¯ä»¥ä¸ã®éãã
http://gcal2json.ning.com/json/gcalendar?callback=handleCalendarResult
ãã©ã¤ãã·ã¼ä¿è·ã®ãããå¼ã³åºãå´ã®ã¢ããªã±ã¼ã·ã§ã³ã¯ã¦ã¼ã¶ã®åæãå¾ãªãã¨ã¹ã±ã¸ã¥ã¼ã«æ å ±ãåå¾ã§ããªãããã«ãªã£ã¦ããã
ã¹ã±ã¸ã¥ã¼ã«æ å ±ãåå¾ããã®ã«å¿ è¦ãªã®ã¯JavaScriptã³ã¼ãã®ã¿ãèªè¨¼ã®ããã®è¤éãªãããã³ã«ãå®è£ ããå¿ è¦ã¯ãªãã
ã³ã¼ãä¾ï¼
<html> <head> <title>Google Calendar JSONP client sample</title> <script type="text/javascript"> function $(id) { return document.getElementById(id) }; function escapeHTML(str) { return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">"); } function requestCalendarFeed() { var script = document.createElement('script'); script.type='text/javascript'; script.charset='utf-8'; script.src='http://gcal2json.ning.com/json/gcalendar?callback=handleCalendarResult'; document.getElementsByTagName('head')[0].appendChild(script); } function handleCalendarResult(result) { if (result.error) { alert(result.error.message); var url = result.error.subscriptionUrl; url += '?resource_name=gcalendar&application_url='; url += encodeURIComponent(location.href.replace(/[^\/]+$/, '')); url += '&return_url='; url += encodeURIComponent(location.href); $('view').innerHTML='<a href="'+url+'">Please grant calendar access to us!</a>'; } else { var html = '<ul>'; for (var i=0; i<result.entry.length; i++) { html += '<li>'+escapeHTML(result.entry[i].title)+'</li>'; } html += '</ul>'; $('view').innerHTML=html; } } </script> </head> <body onload="requestCalendarFeed()"> <div id="view"></div> </body> </html>
â GoogleカレンダーJSONクライアントのサンプル
gcal2json.ning.com ã¯Googleã«ã¬ã³ãã¼ã«æ¥ç¶ãã¦ã¹ã±ã¸ã¥ã¼ã«ãã¼ã¿ãåå¾ããJSONå½¢å¼ã§å¤é¨ã¢ããªã±ã¼ã·ã§ã³ã«é ä¿¡ãããããã·ãµã¼ãã¹ãGoogle Account Authentication ã§ã®èªè¨¼å¦çããã³ãã©ã¤ãã¼ããã£ã¼ãã®åå¾ã¯ãã®ãµã¼ãã¹ã代è¡ãããããã¦åã¢ããªã±ã¼ã·ã§ã³ã«å¯¾ãã¦ãã¦ã¼ã¶ãè¨å®ããã¢ã¯ã»ã¹å¶å¾¡ã®ããªã·ã¼ãèæ ®ããä¸ã§ãã®ãã£ã¼ããåé ä¿¡ããã
ãã®ããã
Google â gcal2json.ning.com (Googleã«ã¬ã³ãã¼JSONãããã·ãµã¼ãã¹) gcal2json.ning.com â (JSONPãªã¯ã¨ã¹ããçºè¡ããã¢ããªã±ã¼ã·ã§ã³)
ã®ï¼ã¤ã®é·ç§»ã®éã«ã¦ã¼ã¶ã®åæç»é¢ãæã¾ã£ã¦ãã¾ããã¨ã«ãªããã¡ãã£ã¨ã¤ã³ã¿ã¼ãã§ã¼ã¹çã«ãã©ãããããã¯å®é¨ã¨ãããã¨ã§å¾¡å®¹èµ¦ã
ãã®ãµã¼ãã¹ã®å©ç¨ã±ã¼ã¹ã¨ãã¦èããããã®ã¯ãä¾ãã°ããµã¤ãã¸ã®è¨ªåè ã«å¯¾ãã¦ãã¹ã±ã¸ã¥ã¼ã«ã®ç©ºãæéã«éå¬ããã¦ããããããã¤ãã³ãã表示ãããã¼ã½ãã©ã¤ãºãµã¼ãã¹ãªã©ã