Reputation: 14317
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)
Upvotes: 7
Views: 2802
Reputation: 3340
Seams Google Custom Search not support Google Shopping.
But here is a third party API(not official API):
https://serpapi.com/shopping-results
Price:
Upvotes: 0
Reputation: 8246
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.
Upvotes: 3