2006/12/27

Google Calendar 的 JSON 應用


新版的 blogger.com 有個 HTML/Javascript 的 widget 區塊,可以很自由的放入一些程式碼,目前 google 宣佈全面支援 JSON 的規格,因此不用再利用 XMLRequest 的元件去解惱人的 XML 格式。

目前 blogger.com 的新版範本檢查的很嚴格,很多要寫死的資料並不建議直接放在範本上,利用 HTML/Javascript 這個 widget 也是放置資料的好方法。

JSON 的規格大致上就是利用Javascript src=http://domain.../?param=value 這種模式,用瀏覽器的內建解析HTML語法的同時就把程式碼下載到Client端,然後透過 Callback function 的宣告,只要下載回來就會觸發相關的function,資料利用 Array 的模式直接放在裡面,很簡單的取出資料然後做相關的應用顯示出來即可,要取多少資料,要如何排序,要怎樣顯示?都可以自己決定。

以下就是我利用 Google Calendar 提供的 feed,把最近三筆在日曆上的行程顯示出來,如何判斷最近?就是利用客戶端電腦的日期時間來判斷,然後依照時間排序顯示出這些資訊。程式碼如下:

<h2><a target="_blank" href="http://www.google.com/calendar/embed?src=mpmigkt2int30a57lakat0dn10%40group.calendar.google.com">《活動行程》</a><a target="_blank" href="http://www.google.com/calendar/feeds/mpmigkt2int30a57lakat0dn10%40group.calendar.google.com/public/full"><img border="0" src="http://www.google.com/calendar/images/xml.gif"/></a></h2>
<div id="divcalendar">下載中...</div>
<script>
function cal_Date(a){
var aa=a;
if (aa.length==10)
aa += 'T00:01:00.000+08:00';
return Date.parse(aa.replace(/^(\d{4})-(\d{2})-(\d{2})T([0-9:]*)([.0-9]*)(.)(.*)$/, '$1/$2/$3 $4 GMT'));
}
function cal_comp(a,b){
order= cal_Date(a.gd$when[0].startTime)- cal_Date(b.gd$when[0].startTime);
return order;
}
function cbcalendar(json)
{
var temp = '<ul id="feedItemListDisplay">';
var postshow=3;
var sortentry=json.feed.entry.sort(cal_comp);
var nowDate= new Date();
var j=0;
for (var i=0,post; post = sortentry[i]; i++) {
if(j>=postshow) break;
var title=post.title.$t;
var link=post.gd$where[0].valueString;
var startTime=post.gd$when[0].startTime;
var thisDate = cal_Date(startTime);
if (thisDate >= nowDate)
{
temp += '<li><a target="_blank" href="' + link + '">' + startTime.substring(0,10)+':'+title + '</a><br>' +'</li>';
j ++;
}
}
if (j==0)
temp += "<li>無資料</li>";
temp+="</ul>";
document.getElementById("divcalendar").innerHTML = temp;
}
</script>
<script src="http://www.google.com/calendar/feeds/mpmigkt2int30a57lakat0dn10%40group.calendar.google.com/public/full?alt=json-in-script&callback=cbcalendar" type="text/javascript"></script>

由於 google calendar 並沒有網址URL 的欄位,我是利用地點這個欄位來放網址,上面有行程式碼
var link=post.gd$where[0].valueString;

可以改成
var link=post.link[0].href;

就是 google calendar 那個行程的連結。

相關說明:http://code.google.com/apis/gdata/json.html

總共有113個迴響

  1. 豬小草 12/28/2006 11:27 下午

    好厲害!不知道你找到怎麼從黑米直接發佈書籤到blogspot的方法了沒?

  2. 水瓶子 12/29/2006 10:30 上午

    這個要問葛力吧!他以前有做
    http://www.hemidemi.com/tools/blog_bookmark_setting_blogtype

    可是我沒有試過,可能新版的 blogspot 部落格會不行吧!

  3. 豬小草 12/30/2006 9:32 上午

    對啊就是因為新版的不行,所以讓人好頭痛。又不知道要去哪裡找到blogspot的xpml(是這樣寫?)

  4. 水瓶子 12/30/2006 11:27 上午

    豬小草,來看看這個吧!

    http://code.google.com/apis/gdata/blogger.html

    如果葛力沒有時間寫,也可以幫忙他寫啊!去讀出黑米的Feed 然後用上面這些 API 自己塞到 blogspot.com 的部落格

  5. 豬小草 1/03/2007 12:53 上午

    什麼意思?完全聽不懂。。。

  6. 水瓶子 1/03/2007 10:20 下午

    基本上這是我跟葛力之間的外星語,地球人是聽不懂的,台灣的政治人物也是外星人,但我們不同族,所以雖然他們聽不懂,但都會發表沉長的批評言論。而我們這一族外星人(克隆黑米星系人)發表的言論都是很簡短的。

  7. 匿名 @ 12/22/2012 3:12 上午

    Suggested ages 5 to 10 Kate Kate The Fashion Plate, "I Have To Be Me" is the first in a series about an aspiring tween aged fashion designer in New York City. ghd hair Handbags are one of the wisest investments a woman can make for her wardrobe. ghd straighteners cheap The spacious 22,000-square-foot restaurant and party bar encompasses two levels and an expansive outdoor patio overlooking the steamy Sirens of TI show and one of the busiest stretches of the Las Vegas Strip. north face jackets Their motto is they make designs for women with "way too much attitude." A.. north face sale As a half-man/half-bear I am uniquely qualified for such a dual task, though I feel obliged to point out to you, my Snarky audience, that this particular article was written for bears by a (half-)bear.

  8. 匿名 @ 12/22/2012 10:47 上午

    We a team of professionals from US and Sudan. http://www.oneghdhair.com Another beautiful development pertaining to men pertaining to spring/summer this year is an excellent great quantity connected with ceramic tiles, pieces and look cell styles. ugg boots I find high tops can look great with lots of different looks. uggs The transcript has been reached such Cialis Surrey Bc Cialis Surrey Bc as good functioning apparent? Needless to the bending of ten being Buy Cialis Buy Cialis consorted with arterial insufficiency. ghd australia Both were like listening to an album that was forced to have 10 songs even though only four of them were good and the band knew it.

  9. 匿名 @ 12/23/2012 6:38 上午

    Posted on February 27 2012 by admin. http://www.oneghdhair.com There is a good reason that these are referred to as foundation garments. ghd hair straighteners This look can be easily incorporated into your look. http://www.verynorthface.com They tells stories of the love that they have given and received, the success that they have achieved and the challenges that they have overcome to get to where they are today.. http://www.manyghdhair.com Patrick and Roxanne Devaney, owners of The Sherlock Holmes Pubs (three locations), the Rose Crown Pub and Devaney's Irish Pub, have embarked on a fresh, new endeavor called Moriarty's Bistro | Wine Bar.

  10. 匿名 @ 12/23/2012 9:25 上午

    Known as the classic Impressionist, Monet cannot help but inspire deep admiration for his talent in those who view his work. cheap north face jackets Fly either direction from the airport he took off from and only West is the nicest area worth viewing. http://www.morenorthface.com Don you want to go to work or to grad school? Stanford red-shirts me, I can get my master degree, too. http://www.morenorthface.com Whilst they were extremely expensive when hair straighteners first turn out to be available towards the public, Less expensive straighteners are easy to find now and causes it to be much easier for any lady or woman to possess a model in their home.. http://www.fitghdhair.com Classic clothing, those who have been in vogue in the 1940 in their hands in 70 you actually have a return to the style of the rest of the world population, for many companies, and thus the prime styles and forms, designed to children, not people.

  11. 匿名 @ 12/24/2012 1:51 上午

    I mean, after all, isn Valley where mall shopping was raised to an art form? It wasn until I moved away from home and made my first trek to Union Square in San Francisco that I discovered what a true department store could be like. http://www.morenorthface.com You find it presents feeling of stability. ugg canada When there is a selected Chanel carrier that you want, that is from the price range, then the initial thing that you ought to do would be to go and appearance on-line because of it. http://www.wellnorthface.com Though it is called bogus jewellery but in fact it a genuine replica on the one of a kind kinds obtaining superb filling out. ghd online Comment Interior Design Sketch Portfolio by Riño Karlo Redo i kinda backed away a little when you did that 1-strike cut at 2:49.

  12. 匿名 @ 12/26/2012 11:51 下午

    When one of his call-ins ends with a suicide, life takes a turn.. north face canada Previously, fashion bods in Great Britain had to shell out for their top end range The Row, if they wanted a slice of Olsen action, coughing up thousands for a cashmere jumper or a handbag.. buy ghd Energetske i uštede u emisiji CO2 koje su postignute su nemerljive, a sama investicija će se isplatiti za oko 5 godina. http://www.oneghdhair.com The decision to show only a single painting while investigating the body of work of an artist who is most famous for her painting is a provocative one. ghd sale Also a member of the American Society of Plastic Surgeons (ASPS), Dr.

  13. 匿名 @ 12/30/2012 1:05 上午

    Perhaps that is the main issue that critics are unable to articulate. http://www.downuggboots.com The more the duo tries to avoid each other, situations tend to bring them together and they are bound to cross paths. ghd straighteners I say to just look up a new location fashion week each week to explore ideas for your business. http://www.morenorthface.com When our consumers ordered custom-tailored rings, we will produce three according to his size and width requirements. ghd hair straighteners One designer who is using her success and influence to make a difference in her home country is Autumn Adeigbo who donates 5% of profits from each dress sold to Women For Women international, a charity which aims to help victims of sexual violence in Africa..

  14. 匿名 @ 2/20/2013 4:32 上午

    xanax online xanax online canada - xanax drug interactions adderall

  15. 匿名 @ 2/20/2013 10:33 上午

    generic xanax drug reactions to xanax - xanax drug test how long does it stay in your system

  16. 匿名 @ 2/20/2013 1:04 下午

    buy tramadol buy tramadol order cheap tramadol online - cheap 100mg tramadol

  17. 匿名 @ 2/21/2013 4:13 上午

    buy xanax online without rx xanax 420chan - xanax side effects overdose

  18. 匿名 @ 2/21/2013 9:43 上午

    tramadol 50 mg buy tramadol for dogs - where to buy tramadol usa

  19. 匿名 @ 2/21/2013 6:36 下午

    generic xanax xanax xr overdose symptoms - xanax side effects while pregnant

  20. 匿名 @ 2/21/2013 8:11 下午

    how to buy xanax online legally xanax side effects joint pain - xanax pills wiki

  21. 匿名 @ 2/21/2013 11:59 下午

    buy tramadol online tramadol 50 mg online pharmacy - tramadol overdose how much is fatal

  22. 匿名 @ 2/22/2013 10:53 上午

    buy generic xanax cheapest xanax online-no prescription - xanax withdrawal wiki

  23. 匿名 @ 2/22/2013 4:00 下午

    buy cheap tramadol cloridrato de tramadol 100mg/2ml - tramadol withdrawal exercise

  24. 匿名 @ 2/23/2013 2:39 上午

    buy carisoprodol carisoprodol hair drug test - soma carisoprodol 250 mg

  25. 匿名 @ 2/23/2013 3:22 上午

    buy tramadol online no prescription tramadol dosage rls - buy tramadol 180 online

  26. 匿名 @ 2/23/2013 7:47 上午

    buy tramadol online what does 100 mg tramadol look like - buy tramadol no prescription

  27. 匿名 @ 2/23/2013 8:23 上午

    xanax alprazolam generic xanax ( by gador - alplax) - xanax withdrawal benadryl

  28. 匿名 @ 2/23/2013 10:10 上午

    buy tramadol online tramadol 50mg 627 - buy tramadol online cod no prescription

  29. 匿名 @ 2/23/2013 6:00 下午

    can you buy xanax online legally buy alprazolam for dogs - brand xanax online no prescription

  30. 匿名 @ 2/23/2013 7:23 下午

    buy tramadol overnight cod buy tramadol online forum - buy tramadol using mastercard

  31. 匿名 @ 2/23/2013 8:43 下午

    generic xanax buy xanax pills - xanax recreational use

  32. 匿名 @ 2/24/2013 12:45 上午

    carisoprodol 350 mg carisoprodol xanax - carisoprodol - v 2410 side effects

  33. 匿名 @ 2/24/2013 3:50 上午

    alprazolam drug xanax 1 mg recreational - drug abuse of xanax

  34. 匿名 @ 2/24/2013 10:40 上午

    generic xanax how to xanax online - xanax dosage vs valium

  35. 匿名 @ 2/24/2013 3:51 下午

    carisoprodol 350 mg carisoprodol prodrug - soma or carisoprodol

  36. 匿名 @ 2/24/2013 4:50 下午

    buy tramadol online tramadol hcl tab 50mg side effects - tramadol dosage equivalent

  37. 匿名 @ 2/24/2013 5:25 下午

    generic xanax xanax pills do they do - white round 2mg xanax

  38. 匿名 @ 2/24/2013 5:34 下午

    order tramadol no prescription can i buy tramadol over the counter usa - tramadol hydrochloride 100mg used

  39. 匿名 @ 2/24/2013 6:54 下午

    buy tramadol online tramadol hcl 50 mg espanol - can you buy tramadol in greece

  40. 匿名 @ 2/24/2013 7:27 下午

    generic xanax buy xanax legally - xanax youtube

  41. 匿名 @ 2/25/2013 4:24 上午

    carisoprodol 350 mg buy carisoprodol usa - do drug tests test carisoprodol

  42. 匿名 @ 2/25/2013 8:08 上午

    buy tramadol online tramadol side effects high - buy tramadol australia

  43. 匿名 @ 2/25/2013 9:45 上午

    generic xanax xanax withdrawal heart rate - long does xanax 1mg work

  44. 匿名 @ 2/25/2013 11:02 上午

    buy tramadol online tramadol 50 mg for headaches - ultram-tramadol.us

  45. 匿名 @ 2/26/2013 7:27 上午

    carisoprodol 350 mg what is soma carisoprodol tablets - carisoprodol in drug test

  46. 匿名 @ 2/26/2013 9:46 上午

    buy tramadol online can take tramadol high blood pressure - tramadol 50 mg street price

  47. 匿名 @ 2/27/2013 6:22 上午

    carisoprodol 350 mg carisoprodol 350 mg good - 700 mg carisoprodol safe

  48. 匿名 @ 2/27/2013 6:55 上午

    buy carisoprodol carisoprodol 350 mg controlled substance - soma carisoprodol controlled substance

  49. 匿名 @ 2/27/2013 10:19 下午

    buy carisoprodol buy carisoprodol without rx - carisoprodol side effects

  50. 匿名 @ 2/27/2013 11:45 下午

    buy tramadol online generic for tramadol hcl - tramadol 50 mg bula

  51. 匿名 @ 2/28/2013 12:58 下午

    buy cialis cheap cialis online best price - ho comprato cialis online

  52. 匿名 @ 2/28/2013 10:04 下午

    buy tramadol online tramadol 100 mg bijsluiter - g e tramadol hcl

  53. 匿名 @ 2/28/2013 10:41 下午

    xanax online order generic xanax online - xanax dosage mg

  54. 匿名 @ 3/01/2013 5:00 上午

    cialis online buy cialis malaysia - generic cialis usa online pharmacy

  55. 匿名 @ 3/01/2013 1:13 下午

    how to buy xanax online legally xanax schedule two drug - alprazolam 1mg tablets side effects

  56. 匿名 @ 3/02/2013 7:55 下午

    cialis online cialis price germany - cheap cialis tablets

  57. 匿名 @ 3/03/2013 12:44 上午

    buy cialis online cialis daily versus - generic cialis usa online pharmacy

  58. 匿名 @ 3/03/2013 1:40 上午

    buy cialis online cialis online overnight shipping - cialis price thailand

  59. 匿名 @ 3/03/2013 2:21 上午

    xanax online does xanax show up parole drug test - xanax bars withdrawals

  60. 匿名 @ 3/03/2013 8:57 下午

    xanax online xanax side effects in children - xanax 2mg bars yellow

  61. 匿名 @ 3/03/2013 11:42 下午

    cialis online cialis daily 2.5 - cialis online satis

  62. 匿名 @ 3/04/2013 5:53 下午

    cialis online cialis daily risks - generic cialis date

  63. 匿名 @ 3/05/2013 12:03 下午

    tramadol 50mg taking tramadol for dogs - tramadol 100 mg high

  64. 匿名 @ 3/05/2013 11:11 下午

    best buy tramadol tramadol overnight delivery - buy tramadol online mastercard

  65. 匿名 @ 3/06/2013 4:15 上午

    http://buytramadolonlinecool.com/#73892 tramadol dosage forms - tramadol dosage premature ejaculation

  66. 匿名 @ 3/06/2013 2:58 下午

    buy tramadol how much tramadol dosage - tramadol hydrochloride 50 mg addiction

  67. 匿名 @ 3/06/2013 3:03 下午

    buy tramadol buy tramadol online in usa - cheap tramadol with no prescription

  68. 匿名 @ 3/08/2013 9:43 上午

    buy tramadol in florida tramadol hcl amneal - buy tramadol from usa

  69. 匿名 @ 3/08/2013 3:21 下午

    buy tramadol side effects for tramadol 50mg - tramadol 50 mg in dogs

  70. 匿名 @ 3/09/2013 7:14 上午

    buy tramadol buy tramadol online usa - tramadol withdrawal long does last

  71. 匿名 @ 3/09/2013 9:56 上午

    buy tramadol tramadol 50 mg ultram - tramadol 50 mg is used to treat

  72. 匿名 @ 3/09/2013 9:59 上午

    buy tramadol can you buy tramadol over counter us - buy tramadol no prescription 100 mg

  73. 匿名 @ 3/09/2013 2:51 下午

    buy tramadol online tramadol 600 mg daily - buy tramadol london

  74. 匿名 @ 3/09/2013 3:45 下午

    http://buytramadolonlinecool.com/#30807 seizure after overdose tramadol - tramadol 600mg

  75. 匿名 @ 3/10/2013 4:06 上午

    buy tramadol tramadol hcl 50mg for dogs - how to order tramadol online no prescription

  76. 匿名 @ 3/10/2013 6:33 上午

    http://blog.dawn.com/dblog/buy/#34852 discount code for next day tramadol - venta tramadol online

  77. 匿名 @ 3/10/2013 8:09 下午

    order tramadol no prescription can you buy tramadol online - tramadol hcl 37.5-3 tab myla

  78. 匿名 @ 3/11/2013 1:32 上午

    learn how to buy tramdadol buy tramadol in usa - tramadol withdrawal upset stomach

  79. 匿名 @ 3/11/2013 4:34 上午

    http://buytramadolonlinecool.com/#30807 buy tramadol overnight - tramadol 50 mg usa

  80. 匿名 @ 3/11/2013 9:20 上午

    buy tramadol rx buy tramadol thailand - tramadol hcl neuropathy

  81. 匿名 @ 3/11/2013 10:53 上午

    learn how to buy tramdadol tramadol 50mg 100ct - generic brand for tramadol

  82. 匿名 @ 3/11/2013 11:16 下午

    buy tramadol saturday delivery cheap tramadol usa - buy tramadol cod fedex

  83. 匿名 @ 3/12/2013 12:53 上午

    buy tramadol online best way buy tramadol online - tramadol cream

  84. 匿名 @ 3/12/2013 4:34 上午

    ways to buy ativan online ativan side effects 1 mg - ativan overdose symptoms

  85. 匿名 @ 3/12/2013 6:14 上午

    cheap tramadol online tramadol sale no prescription - tramadol 50mg dosage for dogs

  86. 匿名 @ 3/12/2013 6:35 下午

    http://buytramadolonlinecool.com/#56411 tramadol withdrawal wellbutrin - tramadol for dogs best price

  87. 匿名 @ 3/12/2013 7:34 下午

    buy tramadol in florida tramadol overdose help - buy tramadol cod shipping

  88. 匿名 @ 3/12/2013 8:19 下午

    buy tramadol mastercard buy generic tramadol - tramadol extended release tablets dosage

  89. 匿名 @ 3/12/2013 8:42 下午

    http://reidmoody.com/#92465 ativan xr - lorazepam online bestellen

  90. 匿名 @ 3/13/2013 2:51 上午

    buy ativan online ativan dosage po - overnight ativan order

  91. 匿名 @ 3/13/2013 4:37 下午

    ways to buy ativan online lorazepam 1 mg price walmart - long break ativan addiction

  92. 匿名 @ 3/14/2013 1:44 下午

    cheap ativan online ativan manufacturer - lorazepam 1 mg overdose

  93. 匿名 @ 3/15/2013 10:49 下午

    http://reidmoody.com/#36921 ativan overdose and treatment - ativan good alcohol withdrawal

  94. 匿名 @ 3/16/2013 1:59 上午

    buy xanax online can buy xanax online us - xanax drug symptoms

  95. 匿名 @ 3/17/2013 7:36 下午

    buy tramadol online buy tramadol online with credit card - kids getting high tramadol

  96. 匿名 @ 3/18/2013 4:54 下午

    tramadol buy tramadol 50 mg recreational use - tramadol ultram high

  97. 匿名 @ 3/18/2013 6:40 下午

    buy tramadol online tramadol for dogs and humans the same - what does tramadol 50 mg do to you

  98. 匿名 @ 3/19/2013 6:23 下午

    buy xanax online drug interactions xanax and alcohol - recreational use of xanax xr

  99. 匿名 @ 3/20/2013 2:23 上午

    http://staam.org/#90723 tramadol side effects - high with tramadol

  100. 匿名 @ 3/20/2013 4:19 上午

    buy tramadol online no prescription cod long does tramadol overdose take - tramadol online cod payment

  101. 匿名 @ 3/20/2013 5:43 下午

    buy tramadol saturday delivery tramadol hcl side effects - buy tramadol online pharmacy

  102. 匿名 @ 3/20/2013 7:29 下午

    buy tramadol online tramadol hcl 50 mg canine - tramadol renal failure

  103. 匿名 @ 3/21/2013 1:35 上午

    buy tramadol online high on tramadol hcl - tramadol yahoo

  104. 匿名 @ 3/21/2013 6:05 上午

    buy xanax online drug interactions xanax and ambien - xanax withdrawal clonidine

  105. 匿名 @ 3/21/2013 7:06 上午

    buy xanax online clarithromycin and xanax drug interactions - xanax drug narcotic

  106. 匿名 @ 3/21/2013 10:22 下午

    buy xanax online xanax side effects user reviews - xanax xr dosage anxiety

  107. 匿名 @ 3/22/2013 5:09 下午

    buy xanax bars online no prescription does xanax show up in hair drug test - xanax dosage recreational

  108. 匿名 @ 3/22/2013 6:16 下午

    buy xanax online xanax withdrawal clonidine - xanax and alcohol toxicity

  109. 匿名 @ 3/26/2013 3:08 上午

    can you really buy xanax online xanax 60 minutes - xanax online no membership

  110. 匿名 @ 3/26/2013 5:24 下午

    buy xanax bars online no prescription xanax drug bust - xanax 1mg buy online

  111. 匿名 @ 3/27/2013 12:16 上午

    buy xanax online xanax dosage airplane anxiety - alprazolam 0 5mg pra que serve

  112. 匿名 @ 5/02/2013 5:22 下午

    pharmacie cialis cialis cialis paris

  113. 匿名 @ 5/10/2013 9:42 上午

    buy tramadol overnight delivery buy tramadol cheap - cheap tramadolonline