Google-api-ruby-client: insufficientPermissions on Google Analytics - User does not have sufficient permissions for this profile.

Created on 15 Aug 2014  路  3Comments  路  Source: googleapis/google-api-ruby-client

I implemented a following rake task:

namespace :ga do
  task :test do
    require 'google/api_client'

    client = Google::APIClient.new(
      application_name: 'Sample Google Analytics',
      application_version: '1.0.0'
    )
    key = Google::APIClient::KeyUtils.load_from_pkcs12(
      'path/to/secret.p12',
      'notasecret'
    )
    analytics = client.discovered_api('analytics', 'v3')

    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: '[email protected]',
      signing_key: key
    )
    client.authorization.fetch_access_token!

    result = client.execute(
      api_method: analytics.data.ga.get,
      parameters:
        {
          ids: 'ga:[8 digit property number]',
          'start-date' => '2014-07-01',
          'end-date' => '2014-07-30',
          metrics: 'ga:visitors,ga:visits,ga:pageviews',
          dimensions: 'ga:pagePath,ga:pageTitle',
          sort: '-ga:pageviews'
        }
    )
    body = JSON.parse(result.response.body)
    puts body
  end
end

And exec:

$ bundle exec rake ga:test
{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"insufficientPermissions", "message"=>"User does not have sufficient permissions for this profile."}], "code"=>403, "message"=>"User does not have sufficient permissions for this profile."}}

Why did the results say "User does not have sufficient permissions for this profile." ?

  • I set full permissions, manage users, edit, collaborate, read & analyze, to issuer (read & analyze may only be required, now anyway, I set full of them)

    • similar problem is here

  • I'd like to execute the rake task on server using cron (so I can't use web auth like flow)
triage me

Most helpful comment

ah.. I misused id. sorry.

ids: 'ga:[8 digit property number]',

I used ids as XXXX of UA-XXXX-Y. Now I use View ID (Admin > VIEW > View Settings) and it works.

All 3 comments

ah.. I misused id. sorry.

ids: 'ga:[8 digit property number]',

I used ids as XXXX of UA-XXXX-Y. Now I use View ID (Admin > VIEW > View Settings) and it works.

I had the same issue, so right [8 digit number] you can take from url, visiting your site analitic main page, there will be 8 digests after "p" letter, i hightlight them
screenshot at 21-57-18
Thus it will be looked as ids: 'ga:92936084'
Wish it helps guys come from Search Engins :+1:

I am facing the same problem. But I don't understand what you guys are talking about

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pacuna picture pacuna  路  5Comments

majioa picture majioa  路  6Comments

arjunmenon picture arjunmenon  路  5Comments

jawadakram20 picture jawadakram20  路  6Comments

penakamaayo picture penakamaayo  路  3Comments