4

我想知道是否有人可以提供一个示例,说明如何使用 GAN 发布者 ID 和 ruby​​(google-api-ruby-client)从 Google Shopping API 中提取产品。我收集您需要使用 oauth 进行身份验证。文档非常稀少,因此我们将不胜感激。

4

2 回答 2

1

客户端购物 API 的基本使用很简单。

require 'google/api_client'

client = Google::APIClient.new
client.authorization = nil

shopping = client.discovered_api("shopping", "v1")
result = client.execute(:api_method => shopping.products.list,
                        :parameters => { "source" => "public" })

要通过 GAN 发布者 ID 查询,您需要进行身份验证,如您所知。您可以为此使用 OAuth 2。您可以在http://code.google.com/p/google-api-ruby-client/wiki/OAuth2查看 ruby​​ 客户端的示例。用于购物的范围是:

 https://www.googleapis.com/auth/shoppingapi

您可以使用 API 资源管理器快速尝试一下:

http://code.google.com/apis/explorer/#_s=shopping&_v=v1&_m=products.list
于 2012-04-12T22:20:41.080 回答
0

使用 0.9.11 版本更容易

require 'google/apis/content_v2'

def list_products
  content_for_shopping = Google::Apis::ContentV2::ShoppingContentService.new
  content_for_shopping.authorization = get_authorization(%w(https://www.googleapis.com/auth/content))
  content_for_shopping.authorization.fetch_access_token!

  content_for_shopping.list_products(ENV['GOOGLE_MERCHANT_CENTER_ID'])
end

def get_authorization(scopes)
  cert_path = Gem.loaded_specs['google-api-client'].full_gem_path + '/lib/cacerts.pem'
  ENV['SSL_CERT_FILE'] = cert_path
  authorization = Google::Auth.get_application_default(scopes)
  # Clone and set the subject
  auth_client = authorization.dup
  return auth_client
end
于 2016-08-26T18:25:50.123 回答