我想知道是否有人可以提供一个示例,说明如何使用GAN publisher ID和ruby ( Google - API -ruby-client)从google Shopping api中提取产品。我收集到您需要使用oauth进行身份验证。documentation非常稀疏,因此任何帮助都将不胜感激。
发布于 2012-04-13 06:20:41
在客户端中基本使用购物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 publisher ID查询,您需要进行身份验证,因为您知道。为此,您可以使用OAuth 2。您可以在http://code.google.com/p/google-api-ruby-client/wiki/OAuth2上查看ruby客户端的示例。用于购物的范围是:
https://www.googleapis.com/auth/shoppingapi
您可以使用APIs非常快速地进行尝试:
http://code.google.com/apis/explorer/#_s=shopping&_v=v1&_m=products.list
发布于 2016-08-27 02:25:50
使用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
https://stackoverflow.com/questions/9822714
复制相似问题