Google API Hello World

阅读下列文章

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!



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值