【问题标题】:Using Google Custom Search on Google Shopping在 Google 购物上使用 Google 自定义搜索
【发布时间】:2015-04-13 16:11:28
【问题描述】:

我想进行 API 调用以检索 Google 购物结果(基本上是产品的价格) 我登录到Google Custom Search,创建了一个名为General 的新搜索引擎,并在网站中选择:http://www.google.com/shopping

但是,当我尝试搜索时,我只得到 1 个结果并且没有价格。

如何检索包括商品价格在内的 Google 购物结果?除了报废页面还有其他方法吗? (我认为完全不推荐)

【问题讨论】:

  • 您找到解决方案了吗?谢谢

标签: google-api-java-client google-custom-search


【解决方案1】:

Seams Google 自定义搜索不支持 Google 购物。

但这里是第三方 API(不是官方 API):

https://serpapi.com/shopping-results

价格:

https://serpapi.com/#pricing

【讨论】:

    【解决方案2】:

    您可以从 Google Content API for shopping 获取所有产品详细信息,包括产品价格。下面是一段代码 sn-p 来检索单个产品的详细信息:

      /**
    * 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 模型类。该类看起来像:

    /**
    * 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 Developers 提供的 example 下载完整的源代码并获取代码解释。

    【讨论】:

    • 不会只返回我的产品吗?
    • 是的,它只会退回您帐户的产品。
    • 我正在寻找可以退回所有产品的解决方案。不是我的——因为我没有
    • 不幸的是,这很难得到。
    • 好吧。这就是我一直在寻找的
    猜你喜欢
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多