Google Analytics API:“用户没有足够的权限访问此帐户。” [英] Google Analytics API: "User does not have sufficient permissions for this account."

查看:432
本文介绍了Google Analytics API:“用户没有足够的权限访问此帐户。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Ruby应用,访问Google AnalyticsAPI以提取一些实验信息。



该应用使用Google服务帐户通过以下功能:

  def connect 
...
@@ client = Google :: APIClient.new (:application_name =>'My Service App',
:application_version =>'1.0.0')
key_file = Rails.root.join('config','privatekey.p12')。 to_s
key_secret ='somesecret'
key = Google :: APIClient :: PKCS12.load_key(key_file,key_secret)
asserter = Google :: APIClient :: JWTAsserter.new(
SECRETS [:google_service_account_email],
['https://www.googleapis.com/auth/yt-analytics.readonly',
'https://www.googleapis.com/auth/analytics。 readonly'
],
key

@@ client.authorization = asserter.authorize()
...
end

...认证并发现两个API都没有问题。



针对YouTube Analytics API使用客户端毫无问题。使用相同的确切帐户通过...访问Analytics API ...

  response = @@ client.execute({
#'analytics是通过discover_api()
:api_method => analytics.management.experiments.list,
:parameters => {
'accountId'=> 'AAAAAAAA',
'profileId'=>'PPPPPPPP',
'webPropertyId'=>'UA-WWWWWWWW-#'
}
})

结果为403错误回应:

  {domain:global,reason:insufficientPermissions,message:用户对此帐户没有足够的权限。} 

关于授权,我已经仔细检查了帐户 service@myapp.com




  • 具有对Google Analytics网络界面的完全权限。我使用 service@myapp.com 帐户,并能够查看相同的实验I试图列出。

  • 已启用Analytics API。在API控制台中,我在服务部分确认了 Analytics API 项目被切换到ON。 (就像YouTube Analytics一样)。

  • 我正在使用适当的AccountID,ProfileID和WebPropertyID值。直接从Google Analytics网络界面复制。



鉴于服务帐户可以访问至少一个API(YouTube分析),并且关联的帐户(service@myapp.com)可以访问Analytics网络界面,特别是访问Google Analytics API的服务帐户似乎有问题。



有什么想法?



类似主题:



  • 分析cs博客文章,查看权限的评论部分
  • 确保您可以提供服务帐户电子邮件(如1234567890@developer.gserviceaccount.com)的权限,以便从GA视图中读取/写入。



    管理员>查看>用户管理>添加权限:


    I'm writing a Ruby app that accesses the Google Analytics API to pull down some experiment information.

    The app connects and authenticates using a Google Service Account via the following function:

    def connect
      ...
      @@client = Google::APIClient.new(:application_name => 'My Service App', 
                                        :application_version => '1.0.0')
      key_file = Rails.root.join('config', 'privatekey.p12').to_s
      key_secret = 'somesecret'
      key = Google::APIClient::PKCS12.load_key(key_file, key_secret)
      asserter = Google::APIClient::JWTAsserter.new(
        SECRETS[:google_service_account_email],
        ['https://www.googleapis.com/auth/yt-analytics.readonly',
         'https://www.googleapis.com/auth/analytics.readonly'
        ],
        key
      )
      @@client.authorization = asserter.authorize()
      ...
    end
    

    ...which authenticates and discovers both APIs without issue.

    Using the client against the YouTube Analytics API works without issue. Using the same exact account to access the Analytics API via...

    response = @@client.execute({
      # 'analytics is the API object retrieved via discover_api()
      :api_method => analytics.management.experiments.list, 
      :parameters => {
        'accountId' => 'AAAAAAAA',
        'profileId' => 'PPPPPPPP',
        'webPropertyId' => 'UA-WWWWWWWW-#'
      }
    })
    

    Results in a 403 error response:

    {"domain":"global","reason":"insufficientPermissions","message":"User does not have sufficient permissions for this account."}
    

    In regards to authorization, I have double-checked the account service@myapp.com:

    • Has full permissions to the Google Analytics web interface. I logged in using the service@myapp.com account and was able to view the same Experiments I attempted to list.
    • Has enabled the Analytics API. Within the API Console, I confirmed in the Services section that the Analytics API item is switch to ON. (Just like YouTube Analytics is.)
    • I am using the appropriate AccountID, ProfileID, and WebPropertyID values. Copied directly from the Google Analytics web interface.

    Given that the service account can access at least one API (YouTube Analytics), and the associated account (service@myapp.com) can access the Analytics web interface, there seems to be something wrong with the service account accessing the Analytics API in particular.

    Any ideas?

    Similar topics:

    解决方案

    Make sure you give the service account email (something like 1234567890@developer.gserviceaccount.com) permissions to read/write from your GA view.

    Admin > View > User Management > "Add permissions for:"

    这篇关于Google Analytics API:“用户没有足够的权限访问此帐户。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆