Coding in the Shade: Using Eclipse with Google Data APIs
来源:互联网 发布:php文件上传类库 编辑:程序博客网 时间:2024/04/30 02:35
Introduction
Eclipse is a very handy (and free!) IDE that has a special place in the hearts of many Java programmers. It is not a surprise then, that you might want to use it with the Java client library to make a killer Java application that works with one of the Google Data APIs.
Setting up Eclipse
If you don't have Eclipse installed yet, you've been missing out. Eclipse can make Java development a lot easier, due to its ability to suggest fixes, find missing imports, and autocomplete methods. Go to the Eclipse.org downloads page to get the installer for your operating system. To run Eclipse you'll have to have a JRE installed, which is linked to from the Eclipse downloads page. Once you've installed Eclipse, you'll need to create a workspace. These examples use /usr/local/eclipse/workspace
.
Installing required libraries
Eclipse provides a lot of Java functionality out of the box, so this should be easy. First things first, grab the latest version of the Java client library from the project downloads page. Note that there are two separate downloads: one for samples, and one for the source code. Download the samples zip, since that includes the compiled JAR files of the Java client library needed to create your own programs. If you are curious about how the client library itself works, you can download the source zip and look through it, but that is outside the scope of this article. Once you've downloaded the samples zip, unzip the file to a convenient directory where you can find the files. The examples use /usr/local/eclipse
. This means the JAR files for the project should now be accessible under /usr/local/eclipse/gdata/java/lib
.
Now that you have installed the client library, the next thing to do is download some external dependencies so we can include them in the project build path. The INSTALL-samples.txt
file contains a list of jars you'll need and locations to download them from. The current list is:
In this example, these JAR files are downloaded and copied to /usr/local/eclipse/gdata/third_party
.
Whew! Now you should have all the pieces you need to start developing a Java application that uses one of the Google Data APIs. Read on!
Creating a new application
The first step is to open Eclipse and select "New > Java Project" from the File menu.
Now click Next and select the Libraries tab. Add in all of the dependent JAR files you downloaded by clicking on Add External JARs.
You also will have to add in the JAR files from the Java client library. They are located in the java/lib
subdirectory of where you extracted the client library. You will always have to include the following JAR files: gdata-client, gdata-client-meta, gdata-core, and gdata-media.
Now choose which API you wish to use. This example uses the Google Documents List API. This requires adding in the appropriate JAR files: gdata-docs and gdata-docs-meta.
Finally you can click "Finish" and create your new project.
To make a simple test application, create a new class with a main method by selecting "New > Class" from the File menu.
Now I'm going to paste in some code from the Developer's Guide for the Documents List API.
You will see a lot of errors until you add the appropriate import statements. Eclipse makes this easy, all you have to do is click on the error markers on the left to get a helpful menu that lets you add imports.
Once you have cleaned up the imports, you also have to handle exceptions that can be thrown by our code. The example opts to surround the entire sample code with a very rudimentary exception handler.
Now, assuming that you substitute the username and password with a valid test account you have created, you should be able to see a list of documents owned by that test account when you choose "Run" from the Run menu.
Hooray!
Conclusion
Now that you have a working instance of Eclipse and all the required JAR files in place, you are well on your way to building an awesome Java application that works with one of the Google Data APIs.
- Coding in the Shade: Using Eclipse with Google Data APIs
- Google Advertising Tools: Cashing in with Adsense, Adwords, and the Google APIs [ILLUSTRATED]
- Installing the google coding style settings in Eclipse
- Using the Runtime APIs
- Reading files in JavaScript using the File APIs
- Working with Data in ASP.NET 2.0 :: Using TemplateFields in the GridView Control
- Using Renewable Energy in the Data Center
- (转)Using cURL to interact with Google Data services
- Compressing and Decompressing Data using JavaTM APIs
- Using OAuth 2.0 to Access Google APIs
- Using Legacy C APIs with Swift
- A full-duplex audio player in C# using the waveIn/waveOut APIs
- Google Book Search APIs-----Data API
- Using SOAP Interface with the SQL Server Data Services
- Using the jQuery Validate Plugin with HTML5 Data Attribute Rules
- Coding HTML5 Pages Using Eclipse
- Make Easy Money with Google: Using the AdSense Advertising Program
- Controlling EWF by Using the EWF APIs
- LabVIEW与数据库使用LabSQL
- Hibernate介绍
- 动态规划的中文分词方法
- 半决赛之乌拉圭vs荷兰
- windows mobile 文件包的引用
- Coding in the Shade: Using Eclipse with Google Data APIs
- 解决“无法删除文件:无法读源文件或磁盘”
- Zookeeper分布式安装手册
- gdata-java-client-eclipse-plugin
- 可以讓你少奮鬥十年的經驗
- 2010年7月6日的感悟
- Steps to create a new Google Data Template
- C++ 虚函数表解析
- 前触发器和后触发器简介