Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble authenticating with Google Content API for Shopping
    primarykey
    data
    text
    <p>I'm trying to use <a href="https://developers.google.com/accounts/docs/OAuth2ServiceAccount#libraries" rel="nofollow">OAuth2 for Server to Server Applications</a> in conjunction with <a href="https://developers.google.com/shopping-content/" rel="nofollow">Google's Content API for Shopping</a> using the <a href="http://code.google.com/p/google-api-ruby-client/" rel="nofollow">google-api-client gem</a> and Ruby on Rails 3.2.5. Also, I have already set up my merchant account as prescribed in the Content API documentation.</p> <p>This was the best way I found to be able to:</p> <ul> <li>create/update products in the background</li> <li>have created products fall under my company's Google Products 'umbrella'</li> <li>not require every user to authenticate/authorize when their token expires</li> </ul> <p>Using lines 1 - 23 from <a href="http://code.google.com/p/google-api-ruby-client/source/browse/service_account/analytics.rb?repo=samples" rel="nofollow">this sample</a> as a starting point, I've begun to write the following module for use in background jobs:</p> <pre><code>require 'httparty' require 'google/api_client' module GoogleProducts GOOGLE_CONFIG = YAML.load_file(File.join(Rails.root, "config", "google.yml"))[Rails.env] CLIENT_ID = "XXXXXXXXXXXX@developer.gserviceaccount.com" MERCHANT_ID = "XXXXXXX" SCOPE = "https://www.googleapis.com/auth/structuredcontent" KEY_FILE_PATH = File.join(Rails.root, "config", "my-privatekey.p12") KEY_FILE_PASS = "XXXXXXXXXX" def self.add_item(item_id) self.fetch_token xml = self.gen_item_xml(item_id) headers = {"Content-type" =&gt; "application/atom+xml", "Content-Length" =&gt; xml.length.to_s} url = "https://content.googleapis.com/content/v1/#{MERCHANT_ID}/items/products/generic?access_token=#{$gp_token}" response = HTTParty.post(url, :body =&gt; xml, :headers =&gt; headers).parsed_response end def self.gen_item_xml(item_id) #building product xml end private def self.fetch_token api_client = Google::APIClient.new(:authorization =&gt; :oauth2) key = Google::APIClient::PKCS12.load_key(KEY_FILE_PATH, KEY_FILE_PASS) asserter = Google::APIClient::JWTAsserter.new(CLIENT_ID, SCOPE, key) begin api_client.authorization = asserter.authorize #todo - store in something other than a global $gp_token = api_client.authorization.access_token rescue Signet::AuthorizationError =&gt; e puts e.message ensure return $gp_token end end end </code></pre> <p>Everything seemingly works fine - the authentication, the handling of the auth token - until I attempt to actually add an item, which I get the following when I do:</p> <pre><code>&lt;errors xmlns='http://schemas.google.com/g/2005'&gt; &lt;error&gt; &lt;domain&gt;GData&lt;/domain&gt; &lt;code&gt;ServiceForbiddenException&lt;/code&gt; &lt;internalReason&gt;Could not find authenticated customer&lt;/internalReason&gt; &lt;/error&gt; &lt;/errors&gt; </code></pre> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload