Sample programs for accessing the Content API for Shopping using the Google API Client Library for Java

From this page you can download example programs that demonstrate the usage of the Google API Client Library for Java for accessing the Content API for Shopping. Please see below for information about the individual examples.

Content

  1. Download examples
  2. Basic example
  3. Batch insertion
  4. Batch deletion

Note: All examples are distributed under the Apache License, Version 2.0. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 .

Download examples

Please download the .zip file containing all of the examples. Detailed setup instructions can be found in the Java Developer's Guide.

Basic example

This example is described in detail in the Java Developer's Guide. It has simple functions for inserting, updating, deleting and retrieving data.

The main function of this example, located in com.google.api.client.sample.structuredcontent.basicexample.StructuredContentSample, will generate 30 dummy products, insert all of them, then update all of them with modified values, and delete them again. Also demonstrated is retrieving an item and updating it after modifying some of its values, as well as retrieving the complete list of items by navigating the next-links.

For making the program work, you have to replace the dummy values for username, user homepage, password and account ID with the correct values. That is, find the main function and replace as follows:

Replace ...with ...
1234567your account ID (can be found in merchant center)
your.username@gmail.comyour username
yourPasswordyour password
http://my.supercool.com/homepage/your homepage

Batch insertion

How batching is done in the client libary examples in general is described in the Java Developer's Guide.

This program takes a .csv file containing information about products to be inserted or updated, and will submit all of these products to the Content API for Shopping.

Note: If you don't need any special functions, you can use this program "out of the box" for sending your products by just supplying them in a .csv file.

For submitting products, this program uses a predefined number of threads running in parallel, each of which will send batches containing up to a certain number of products. For example, you can set the program up to use 10 worker threads that will send batches containing up to 50 products.

The main function of this example is located in com.google.api.client.sample.structuredcontent.batchinsert.MultiThreadingAndBatchingExample. For making the program work, you have to replace the dummy values for username, user homepage, password and account ID with the correct values. That is, find the main function and replace as follows:

Replace ...with ...
1234567your account ID (can be found in merchant center)
your.username@gmail.comyour username
yourPasswordyour password
http://my.supercool.com/homepage/your homepage

Then you need to call the program with four commandline parameters:

  1. The .csv file containing the products to be inserted.
  2. The separator used in this file, for example ";" or "|".
  3. The number of threads to be used.
  4. The maximum number of products that can be sent in one thread.
An example of valid commandline arguments: myProductFile.csv ; 10 50

The exact format that is expected in the .csv file is explained in the documentation within the class CsvInputAdapter. A sample .csv file is included in the download.

Batch deletion

How batching is done in the client libary examples in general is described in the Java Developer's Guide.

This program will retrieve all products from your account and delete them. More specifically, it will use a normal GET command to retrieve the first page of items, and will then send a single batch that deletes all of these items. It repeats this until there are no items left in the account, i.e. until retrieving the first page results in an empty list.

The main function of this example is located in com.google.api.client.sample.structuredcontent.batchdelete.BatchDeleteSample. For making the program work, you have to replace the dummy values for username, password and account ID with the correct values. That is, find the main function and replace as follows:

Replace ...with ...
1234567your account ID (can be found in merchant center)
your.username@gmail.comyour username
yourPasswordyour password

Send feedback about...

Content API for Shopping