InsufficientPermission(403)试图网站资源连结到AdWords(谷歌广告)的帐户

问题描述 投票:1回答:1

我试图找到什么似乎是一个比较普遍的问题使用分析管理API时的解决方案,遗憾的是没有一个答案是有帮助的。

我使用Google Analytics Management API的使用具有完全访问我的Analytics帐户服务帐户启动。它被授予修改,写作,阅读和分析,并在帐户级别,这意味着他们也都在酒店的水平,鉴于级别继承管理用户的权限。

我能顺利拿到,我有访问权限的帐户,并插入新的网络性能。

但是,我没能到我的谷歌广告帐户连接到任何网络媒体资源。每当我调用API,我收到了403错误:

{"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"User does not have sufficient permissions for this web property."}],"code":403,"message":"User does not have sufficient permissions for this web property."}}

我查了很多次,什么权限我的服务帐户每个级别(帐户,媒体甚至视图),总有修改,写作,阅读和分析和管理用户。

下面是我尝试链接谷歌广告帐号:

<?php
require_once __DIR__ . '/vendor/autoload.php';
$KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Management API");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes([
  'https://www.googleapis.com/auth/plus.login',
  'https://www.googleapis.com/auth/analytics',
  'https://www.googleapis.com/auth/analytics.edit',
  'https://www.googleapis.com/auth/analytics.provision',
  'https://www.googleapis.com/auth/analytics.manage.users',
  'https://www.googleapis.com/auth/analytics.readonly'
]);
$analytics = new Google_Service_Analytics($client);
$adWordsAccount = new Google_Service_Analytics_AdWordsAccount();
$adWordsAccount->setCustomerId("XXX-XXX-XXXX");
$adWordsLink = new Google_Service_Analytics_EntityAdWordsLink();
$adWordsLink->setName("TestLink");
$adWordsLink->setAdWordsAccounts([$adWordsAccount]);
try {
  $analytics->management_webPropertyAdWordsLinks->insert(
    999999999, // Analytics Account ID
    "UA-999999999-1", // Tracking ID
    $adWordsLink
  );
} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
        . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}

我知道我肯定要用更多的范围比我更需要,但只用https://www.googleapis.com/auth/analytics.edit给出了相同的结果。

下面是我用(与我已经通过谷歌API控制台生成的密钥)的service-account-credentials.json

{
  "type": "service_account",
  "project_id": "...-230314",
  "private_key_id": "<PRIVATE_KEY_ID>",
  "private_key": "<PRIVATE_KEY>",
  "client_email": "[email protected]",
  "client_id": "<CLIENT_ID>",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/dev-...%40...-230314.iam.gserviceaccount.com"
}

预先感谢您对我们的支持!

多利安

google-analytics google-analytics-api google-adwords
1个回答
0
投票

为了能够链接谷歌Analytics(分析)和谷歌广告进行链接的帐户必须在谷歌Analytics(分析)网络媒体资源的编辑器(东西显然你已经这样做),但也需要在谷歌广告帐户的管理员。

不是你的个人/企业谷歌帐户,但在这种情况下,服务帐户本身。电子邮件你包含在你的凭据财产client_email

参考:Google Help Center

警告:

我不是100%肯定,你甚至可以做到这一点。谷歌广告可能需要确认从用户到Bé加入到一个帐户,而事实上,你没有访问该服务帐户的邮箱可以让你从事任何确认。我还是那句话我不知道这一点,所以我会尝试,但如果你不能够添加用户到谷歌广告帐户,你必须找到另一种方法使用自己的电子邮件来验证API调用,而不是服务帐户。

© www.soinside.com 2019 - 2024. All rights reserved.