2009年3月30日 星期一

Google Calendar Api 介紹

如何使用java來控制Google Calendar, 以下兩分投影片提供說明和實際的範例


Google Calendar Api 簡介


Google Calendar Api java 的 範例和程式碼

2009年3月24日 星期二

在java 下 讀取 Google Calendar api 的 XML 資料

前提 import 所需要的liberary
  • google data api
  • JAVAXP

code 如下

// import
import com.google.gdata.util.AuthenticationException;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;



/**
* This is a test template
*/

public class CalendarPureXml {

public static void main(String[] args) throws IOException, SAXException, AuthenticationException {

//---- set proxy if hava proxy-----------------------------------
Properties systemSettings = System.getProperties();
systemSettings.put("proxyPort","80");
systemSettings.put("proxyHost","proxy.quanta.corp");
//---------------------------------------------------------------


//----get XML by network , the example is my calendar------------
URL feedUrl = new URL("http://www.google.com/calendar/feeds/chiachunchuang%40gmail.com/private-6f9ef2889d8ccb2b63254d091d7cfc63/full");

URLConnection con = null;
try {
con = feedUrl.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream is = con.getInputStream();
//----------------------------------------------------------------


//----get XML-----------------------------------------------------
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {

e.printStackTrace();
}

Document doc = docBuilder.parse (is);

//normalize text redivsentation
doc.getDocumentElement ().normalize ();
//-----------------------------------------------------------------


//----print information--------------------------------------------

//print title
System.out.println ("Root element of the doc is " +
doc.getDocumentElement().getNodeName());

System.out.println("-------------------------------------------------");

//--EX 1 get child node---------------------------------------
NodeList UPEntry = (NodeList) doc.getDocumentElement().getChildNodes();
// 取得 item
Node ent=UPEntry.item(1);
System.out.println("child name 1 : " + ent.getNodeName());
System.out.println("child value 1 : " + ent.getTextContent());
//------------------------------------------------------

System.out.println("-------------------------------------------------");

//--EX 2 get node with title---------------------------------------
NodeList entTitle= doc.getElementsByTagName("title");
System.out.println("Total of Title : " + entTitle.getLength());
System.out.println("Title name 0 : " + entTitle.item(0).getNodeName());
System.out.println("Title value 0 : " + entTitle.item(0).getTextContent());
//------------------------------------------------------

System.out.println("-------------------------------------------------");

//--EX3 get entrys count which = entry------
NodeList listOfEntry = doc.getElementsByTagName("entry");
int totalEntrys = listOfEntry.getLength();
System.out.println("Total no of entry : " + totalEntrys);
//------------------------------------------------------------
// get entry value
// listOfEntry.item(int I) 第i個entry but entry 還有很多值
// 重複 getElementsByTagName( Name ) 取得想要的資訊
//------------------------------------------------------------


//-----------------------------------------------------------------

}
}

java 加入 控制 XML package

網路上搜尋一下有幾個 liberary 可以使用
在此介紹 JAVAXP

1.下載JAVAXP
  • 到官方網站下載
https://jaxp.dev.java.net/
  • 下載完執行解壓縮
到DOS下(命令提示字元) 執行
java -jar JAXP_142.jar
● 到所在檔案目錄
● 記得java path 要先設好

2. improt 這個 liberary (...\lib\*.jar檔)

2009年3月23日 星期一

Google Base -Google 的廣告看板

----------------------------------------------------
What is Google Base
----------------------------------------------------
● Base = Database?
● 是資料庫沒錯
依照google 定好的欄位或自行新增欄位 ,填入資料
● 提供任何想張貼的訊息
類似布告欄
● 公開資料

----------------------------------------------------
介紹 轉貼自 http://blue.lins.fju.edu.tw/~mao/google/benefit4user.html
----------------------------------------------------
2005年11月16日, Google Base發表, 允許網友上網張貼任何資訊, 它說「如果你有需要和別人分享的信息,但又不知道從何開始, 那麼Google Base 就是為你量身制作的服務」
目前祗接受英文的資訊, 也只有英文的介面
Google Base 是一個讓用戶自行張貼「任何」資訊的空間, 經由 Google 搜尋引擎查找。雖然號稱「任何」資訊, 仍然有些預期的類型: 見附註


----------------------------------------------------
應用 轉貼自 http://www.digitalcontent.org.tw/e/temp/1214/941214_ourlinx.htm
----------------------------------------------------
本質 上,Google只是提供了一個平台,讓用戶在上面按一定的遊戲規則自由發揮,至於遊戲能玩多大,取決於參與者的想像力。
現在有人在上面賣汽車,有人賣皮 鞋手袋,有人賣珠寶首飾,這些都不算多有創意。
有人徵婚,有人想讓全世界知道「我愛你」,有人想為小貓找個家,有人則要為小貓找男朋友,有人聲稱可以幫你 找工作……,
你的想像力有多大,Google Base就有多大。


----------------------------------------------------
相關資訊
----------------------------------------------------
首頁
http://www.google.com/base/

右下方三個選項
1. "One at a time" 選項可以po 文章或檔案 到google base 裡
2. "Data feed" 比較像資料庫,點進去看就可以看到自己傳的資料
3. "API" 就是 api 的說明教學


官方提供的應用例子

http://google-code-featured.blogspot.com/search/label/base
查詢一些在 google base 上有記錄的資料

如
job center 找工作的
http://www.jobcentral.com/index.asp
BaseEstate 找房子的
http://www.baseestate.com/


不過這些訊息都在美國, 因為只支援 美國、英國,德國

----------------------------------------------------
附註 分類類型 轉貼自 http://blue.lins.fju.edu.tw/~mao/google/benefit4user.html
----------------------------------------------------
blogs [部落格]
Coupons
Clinical trials
Events and activities [事件與活動]
Housing[房屋信息]
Jobs
Mobile content
News and articles[新聞與文章]
Nursing home
People profiles[人]
Podcasts
Protein
Products[商品]
Recipes
Reference articles[參考文獻]
Reviews[評論]
Services[服務]
Vehicles[車輛]
Wanted ads[需求信息]
Wine and food
----------------------------------------------------

Google Youtube Api

YouTube影片檔案格式YouTube接受廣泛的影片檔案格
式如:.WMV、.AVI、.MOV 和 .MPG。 以下是某些可改善運作情形的設定:
MPEG4 (Divx、Xvid) 格式
MP3 音效
影片解析度: 480x360 或更高
畫面速率: 24fps 或更高

其他功能記錄於YouTubeData API.ppt
http://docs.google.com/Presentation?docid=dgrnpzdv_101gqz2bjfs&hl=zh_TW


幾點補充
1. 關於影片下載問題,官方 "沒有提供下載功能" ,不過google 一下就會發現很多工具

2. 所有檔案上傳到youtube都會 轉成 "FLV 檔 "

3. 聲音檔雖然可以上傳,不過上傳後會有編譯錯誤的訊息

4. 聲音檔下載的話,也有 flv 轉 mp3 或 wmv 的工具

6. google voice 最近要推出, 不過還沒有API 提供.....


補充文章(以下皆為轉貼)

下載youtube 影片
http://www.tcgs.tc.edu.tw/~sagit/info/p12.htm

audio files can upload to youtube?
http://www.jakeludington.com/youtube/20080406_can_i_upload_mp3_or_wma_audio_files_to_youtube.html

google voice
https://www.google.com/voice/about