我想进行API调用以检索Google购物结果(基本上是产品的价格) 我登录了Google Custom Search,创建了一个名为General的新搜索引擎,并在网站中进行了选择:http://www.google.com/shopping。
但是,当我尝试搜索时,我只得到1个结果并且没有价格。
如何检索Google购物结果,包括商品价格?有没有其他方式而不是废弃页面? (我认为完全不推荐)
答案 0 :(得分:3)
您可以从Google Content API获取购物的所有产品详细信息,包括产品价格。以下是检索单个产品详细信息的代码段:
/**
* 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);
}
您需要为上述代码编写Product model类。该课程如下:
/**
* 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;
...
...
}
您可以下载整个源代码,并从Google开发者提供的example获取代码说明。
答案 1 :(得分:0)