Google API Hello World

来源:互联网 发布:amd vmware mac os 编辑:程序博客网 时间:2024/05/21 08:32

阅读下列文章

1. 用eclipse写google api client 程序 http://code.google.com/apis/gdata/articles/eclipse.html

2. 如何使用google document list API  http://code.google.com/apis/documents/docs/3.0/developers_guide_java.html

3. 用其他语言写google api client 程序 http://code.google.com/apis/gdata/articles/


阅读完之后,下面写一个最简单的java例子:使用google api来获取你的google account里的document list

1. install eclipse and download google api for java "gdata-samples.java-xxx.zip" file at http://code.google.com/p/gdata-java-client/downloads/list, 解压该zip file (然后我会把"lib" and "deps" 目录下的jar files放到一起,例如放到一个gdata_lib目录下)

2. create new "java project" eclipse,然后把步骤1提到google api jar files添加到java build path library里,另外还需要用到下列3个jar:mail.jar, servlet-api.jar and activation.jar

3. create a simple class to use google api

import java.net.URL;import com.google.gdata.client.docs.DocsService;import com.google.gdata.data.docs.DocumentListEntry;import com.google.gdata.data.docs.DocumentListFeed;public class TestDocumentList {public static void main(String[] args) {DocsService client = new DocsService("document list demo");try {client.setUserCredentials("hkbu.chtl.tomson@gmail.com", "chtl2010");URL documentListFeedUrl = new URL("https://docs.google.com/feeds/default/private/full");DocumentListFeed feed = client.getFeed(documentListFeedUrl,DocumentListFeed.class);for (DocumentListEntry entry : feed.getEntries()) {System.out.println(entry.getTitle().getPlainText());}} catch (Exception e) {e.printStackTrace();}}}

4. run it!



原创粉丝点击