Ruby example to access google shopping api using GAN publisher ID

I was wondering if anyone could provide an example of how to retrieve products from the Google Shopping API using the GAN and ruby ​​publisher ID (google-api-ruby-client). I'm going to, you need to authenticate using oauth. The documentation is very sparse, so any help would be greatly appreciated.

+4
source share
2 answers

Simple use of the API for shopping with the customer.

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 request the GAN publisher ID, you need to authenticate as you know. You can use OAuth 2 for this. You can see an example of this for the ruby ​​client http://code.google.com/p/google-api-ruby-client/wiki/OAuth2 . Area of ​​use for purchase:

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

You can use the API to try this pretty quickly:

 http://code.google.com/apis/explorer/#_s=shopping&_v=v1&_m=products.list 
+1
source

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 
0
source

Source: https://habr.com/ru/post/1402887/


All Articles