AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
1.5K members online now
1.5K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

"error" : "invalid_grant" just started appearing

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

When I access the google analytics API account Im seeing this error:

 
Authorization failed.  Server message:
{
  "error" : "invalid_grant"
}
 
This started happening last friday-ish (Feb 12 2016). Any ideas?
 
Heres the code I have been successfully using for over a year:
 
      @@client = Google::APIClient.new
      @@analytics = @@client.discovered_api('analytics', 'v3')
      key = Google::APIClient::KeyUtils.load_from_pkcs12('lib/certs/oauth/dfc-google-analytics.p12', 'passwordhere')
      @@client.authorization = Signet::OAuth2::Client.new(
        :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
        :audience => 'https://accounts.google.com/o/oauth2/token',
        :scope => 'https://www.googleapis.com/auth/analytics.readonly',
        :issuer => '586220500710-mobliemumtpmqvbvkgen6jf6pn7lbrtt@developer.gserviceaccount.com',
        :signing_key => key)
      begin
        @@client.authorization.fetch_access_token!
      rescue Exception => e
        $log.error("could not get google account access because: #{e}")
        @@client = nil
      end
Now, the exception is thrown and caught with the error message:
 
Authorization failed.  Server message:
{
  "error" : "invalid_grant"
}
 
Any help is appreciated.
Mike