Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Custom Search on Google Shopping

I would like to make an API call to retrieve Google Shopping result (basically the price of the product) I logged in to Google Custom Search, created a new Search engine called General, and chose in websites: http://www.google.com/shopping.

However, when I try to search, I get only 1 result and without the price.

How can I retrieve Google Shopping results including the item price? Is there another way rather than scrapping the page? (which I believe it totally not recommended)

like image 967
Dejell Avatar asked Feb 12 '15 19:02

Dejell


People also ask

How do I use Google Custom Search?

From the Programmable Search Engine homepage, click Create a custom search engine or New search engine. In the Sites to search box, type one or more sites you want to include in the search results. You can include any sites on the web, even sites you don't own. Don't worry, you can always add more later.

How do I get a Google custom search API?

With Google Cloud Operations you can create custom dashboards, set up alerts, and access metrics data programmatically. To access Custom Search JSON API usage data in Google Cloud Operations, select "Resource type: Consumed API" and filter on "service = 'customsearch.googleapis.com'" in the Query Builder.

Is there an API for Google search?

Google Web Search API has been deprecated and replaced with Custom Search API (see http://code.google.com/apis/websearch/).


1 Answers

You can get all the product details from Google Content API for shopping, including the price of the product. Below is a code snippet to retrieve details of a single product:

  /**
* Retrieves the product with the specified product ID from the Content API for Shopping
Server.
*
* @param productId The ID of the product to be retrieved.
* @return The requested product.
* @throws HttpResponseException if the retrieval was not successful.
* @throws IOException if anything went wrong during the retrieval.
*/

private Product getProduct(String productId)
  throws IOException, HttpResponseException {
    // URL
    String url = rootUrl + userId + "/items/products/schema/" + productId;

    // HTTP request
    HttpRequest request = requestFactory.buildGetRequest(new GoogleUrl(url));

    // execute and interpret result
    return request.execute().parseAs(Product.class);
}

You need to write a Product model class for the above code. The class looks like:

/**
* Class for representing a product entry.
*/
public class Product extends BatchableEntry {
    @Key("sc:additional_image_link")
    public List<String> additionalImageLinks;
    ...
    @Key("scp:price")
    public Price price;
    ...
    @Key("scp:product_type")
    public String productType;

    @Key("scp:quantity")
    public Integer quantity;
    ...
    ...
}

You can download the whole source code and get the explanation of the code from this example provided by Google Developers.

like image 93
Utsav Dawn Avatar answered Oct 02 '22 18:10

Utsav Dawn