I was wondering if anyone could provide an example of how to pull products from the Google Shopping API using a GAN publisher ID and ruby (google-api-ruby-client). I'm gathering you need to authenticate using oauth. The documentation is very sparse so any help would be much appreciated.
Asked
Active
Viewed 869 times
4
-
Found a good example using curl here if anyone is interested http://humbuckercode.co.uk/licks/code/google-search-api-for-shopping/ – seogrady Mar 23 '12 at 08:50
-
Don't use that. ClientLogin is not recommended and you should be using the official client anyway. – Bob Aman Mar 24 '12 at 10:51
2 Answers
1
Basic usage of the shopping API with the client is easy.
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" })
To query by GAN publisher ID, you need to be authenticated as you're aware. You can use OAuth 2 for that. You can see a sample of that for the ruby client at http://code.google.com/p/google-api-ruby-client/wiki/OAuth2. The scope to use for shopping is:
https://www.googleapis.com/auth/shoppingapi
You can use the APIs explorer to try this out pretty quickly:
http://code.google.com/apis/explorer/#_s=shopping&_v=v1&_m=products.list

Steve Bazyl
- 11,002
- 3
- 21
- 24
0
With version 0.9.11 is even easier
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

Miguel Senosiain
- 1
- 2