CustomerTool is a command-line tool that lets you perform
the following actions:
insert,
update,
delete,
display an item,
execute a batch command,
and query.
It goes against
the customer-specific items feed, not the
public snippets feed, so the results of a query may differ from the results
of QueryExample because CustomerTool is only
searching for matching items in your own data.
Note that CustomerTool handles 'raw' Atom XML, unlike QueryExample where
the code uses the GData client library to parse the XML
and access its content. The tool takes a raw XML stream as input, validates
it and sends it to the server. When it's done, it outputs a raw XML stream
to standard output.
All of the source files are available to you in the cs/samples/gbase directory of the C# Client Library .
The remainder of this page explains how to use the CustomerTool application. If you're not interested in using it and just want to look at the source code, feel free to skip the rest of this page.
To run CustomerTool, execute gbase_customertool.exe from the cs/lib/Release directory.
Warning: If you use Mono to run the examples, you will most likely get an exception telling you
that it failed to connect to the authorization server (https://www.google.com/). In this case, you will need
to configure your client following the instructions on the Mono Security FAQ.
You can also choose to pass the parameter --auth http://www.google.com/ when you run
gbase_customertool.exe, though be aware that if you do that your google password will be sent
in clear through the internet. Don't use --auth http://www.google.com/ with a Google account or a
password that is important to you.
Whenever you access the items feed, you must be authenticated and provide a valid developer
key for "Installed applications".
The authenticated account should be properly set up for Google Base.
When using CustomerTool, this is done by passing the parameters --user, --password and --key.
gbase_customertool.exe insert|update|delete|batch|get|query [--url base_url] [--auth auth_url] --user username --password password <command-specific options...>
[--url base_url] [--auth auth_url] --user username --password password
| Parameter | Meaning | Notes |
|---|---|---|
key |
Developer Key | You can obtain a developer key here. |
base_url |
Google Base server URL | The default is http://www.google.com/base/, but you can specify another server. |
auth_url |
Authentication server URL | The default is https://www.google.com/accounts, but you can specify another server. |
username |
Customer's Google account's e-mail address. | Required. CustomerTool uses the customer items feed. |
password |
Customer's Google account's password. | Required. CustomerTool uses the customer items feed. |
output_file |
The file where the XML is to be written. | You must use standard output. |
You can search for items that you own using the Customer Feed
To search for items in the customer items feed, run the following command
from the cs/lib/Release directory.
gbase_customertool.exe [query] [standard_options] [<your-query>]
You can use the standard Google Base query parameters.
Here's how it would look as a full command line.
gbase_customertool.exe query --user janedoe@google.com --password xyzxyz --key 837738399 "digital camera"
If you want to see all your items, even those that are not searchable yet, omit the query and run:
gbase_customertool.exe query --user janedoe@google.com --password xyzxyz --key 837738399
You can display a single item if you know that item's item ID. As with updates and deletes, if you don't know the ID, you need to issue a query or insert and then use the information you get from that. The response is a feed containing the item.
To display an entry identified by its ID, run the following command from
the cs/lib/Release directory.
gbase_customertool.exe get [standard_options] item_id
| Parameter | Meaning | Notes |
|---|---|---|
item_id |
The ID of the item to edit. | This is the item's full URL. For example, http://www.google.com/base/feeds/items/11292306253607009080 |
This example displays the item with the URL 11292306253607001000:
gbase_customertool.exe get --user janedoe@google.com --password xyzxyz --key 837738399 http://www.google.com/base/feeds/items/11292306253607001000
To insert a new data item, go to the cs/lib/Release directory
and run the following command:
gbase_customertool.exe insert [standard_options] < input_file
| Parameter | Meaning | Notes |
|---|---|---|
input_file |
The file to read the entry from, in Atom format. | You must use standard input. |
CustomerTool uses a command line structured
like this:
gbase_customertool.exe insert --user janedoe@google.com --password xyzxyz --key 837738399 < acme-laptop.xml
The response returns as an XML feed, complete with the customer and item IDs. Here's the result:
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:g='http://base.google.com/ns/1.0'>
<id>http://www.google.com/base/feeds/items/3623814801431172907</id>
<published>2006-06-09T19:34:29.038Z</published>
<updated>2006-06-09T19:34:29.038Z</updated>
<category scheme='http://base.google.com/categories/itemtypes' term='products'></category>
<title type='text'>Acme 2000 series laptop</title>
<content xmlns='http://www.w3.org/1999/xhtml' type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>The fastest Acme Laptop yet...</div>
</content>
<link rel='alternate' type='text/html'
href='http://provider-website.com/item-info-page.html'></link>
<link rel='self' type='application/atom+xml'
href='http://www.google.com/base/feeds/items/3623814801431172907'></link>
<link rel='edit' type='application/atom+xml'
href='http://www.google.com/base/feeds/items/3623814801431172907'></link>
<author>
<name>Jane Doe</name>
<email>jd@provider-host.com</email>
</author>
<g:item_type type='text'>products</g:item_type>
<g:label>Computer</g:label>
<g:label>Laptop</g:label>
<g:label>fastest laptop</g:label>
</entry>
If an item already exists, you can update the data by changing one or more values in the XML input file and performing an update operation. An update uses the HTTP PUT method. The response is a feed containing the new item.
To identify the correct item, you need to provide the item's complete
URL. That is, you need to provide the base URL and the item ID. If you
don't know them, you can query for the item and then use the information
in the <id> tag:
<id>http://www.google.com/base/feeds/items/11292306253607009080</id>
This URL uniquely identifies this piece of data so that you can accurately update the item:
http://www.google.com/base/ To update an existing entry, run the following command from the cs/lib/Release directory:
gbase_customertool.exe update [standard_options] < input_file
| Parameter | Meaning | Notes |
|---|---|---|
input_file |
The file to read the entry from, in Atom format. | You must use standard input. |
For example, use a URL like this:
gbase_customertool.exe update --user janedoe@google.com --password xyzxyz --key 837738399 < updated-item.xml
If an item already exists, you can delete the item. To identify the correct item, the item in the XML file needs to contain the item's complete URL. That is, you need to provide the base URL and the item ID. The response is an empty feed indicating that the item is no longer available.
If you don't know them, you can query for the item and
then use the information in the <id> tag:
<id>http://www.google.com/base/feeds/items/11292306253607009080</id>
This URL uniquely identifies this piece of data so that you can accurately delete the item:
http://www.google.com/base/ To delete an entry identified by its ID, run the following command from
the cs/lib/Release directory:
gbase_customertool.exe delete [standard_options] item_id
| Parameter | Meaning | Notes |
|---|---|---|
item_id |
The ID of the item to edit. | This is the item's full URL. For example, http://www.google.com/base/feeds/items/11292306253607009080 |
This example deletes the item with the URL 11292306253607001000:
gbase_customertool.exe delete --user janedoe@google.com --password xyzxyz --key 837738399 http://www.google.com/base/feeds/items/11292306253607001000
You can execute multiple operations in a single HTTP request by posting a feed to the Google Base Batch URL: http://www.google.com/base/feeds/items/batch.
A feed posted to this URL should contain a list of entries to insert, update and/or delete, as described in Batch Processing with Google Data APIs.
Run the following command from the cs/lib/Release directory
to execute a batch command.
gbase_customertool.exe batch [standard_options] <input_file >output_file
| Parameter | Meaning | Notes |
|---|---|---|
input_file |
The file to read the entry from, in Atom format. | You must use standard input. |
output_file |
The file where the XML response file is to be written. | You must use standard output. |
All the information CustomerTool needs to execute these operations
must be present in the input_file feed. Refer to the GData
documentation on batch operations for a description of the format
of the input_file and the output_file.
CustomerTool uses a command line structured
like this:
gbase_customertool.exe batch --user janedoe@google.com --password xyzxyz --key 37738399
The response is an XML feed that contains the customer and item IDs. Here's the result:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:openSearch=" http://a9.com/-/spec/opensearchrss/1.0/"
xmlns:g=" http://base.google.com/ns/1.0"
xmlns:batch=" http://schemas.google.com/gdata/batch">
<id> http://www.google.com/base/feeds/items/batch</id>
<updated>2006-07-10T12:05:37.377Z</updated>
<title type="text">My Batch</title>
<link rel="http://schemas.google.com/g/2005#feed"
type="application/atom+xml"
href=" http://www.google.com/base/feeds/items/batch"/>
<link rel="http://schemas.google.com/g/2005#post"
type="application/atom+xml"
href=" http://www.google.com/base/feeds/items/batch"/>
<link rel=" http://schemas.google.com/g/2005#batch"
type="application/atom+xml"
href="http://www.google.com/base/feeds/items/batch/batch"/>
<entry>
<id> http://www.google.com/base/feeds/items/13308004346459454600</id>
<batch:operation type="delete"/>
</entry>
<entry>
<id>http://www.google.com/base/feeds/items/13308004346459458888 </id>
<batch:operation type="delete"/>
</entry>
<entry>
<id>myitem</id>
<title type="text">xyz</title>
<content type="html">456</content>
<batch:operation type="insert"/>
<g:price_units type="text">item</g:price_units>
<g:cuisine type="text">international</g:cuisine>
<g:customer_id type="int">1262428</g:customer_id>
<g:item_type type="text">recipes</g:item_type>
<g:main_ingredient type="text">water</g:main_ingredient>
<g:currency type="text">USD</g:currency>
<g:cooking_time type="intUnit">1 minutes</g:cooking_time>
</entry>
</feed>
Note: The Interactive Google Base data API Demo, written in Javascript, also demonstrates the use of batch operations.