通过 API 从 Google Analytics 获取自定义维度时出现问题
Problems while getting custom dimensions via API from Google Analytics
好日子。当我尝试通过 API 获取自定义尺寸时,出现错误
Exception 'Google_Service_Exception' with message 'Error calling GET
https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/customDimensions:
(400) Cannot query by ~all for id webPropertyId'
我的代码
$service_account_name = '<Service Email>@developer.gserviceaccount.com';
$key_file_location = '<keyName>.p12';
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array(Google_Service_Analytics::ANALYTICS),
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
'<My email>'
);
$client->getAuth()->setAssertionCredentials($cred);
$service = new Google_Service_Analytics($client);
$result = $service->management_customDimensions->listManagementCustomDimensions('~all', '~all');
print_r($result);
获取目标的类似代码可以正常工作
$service_account_name = '<Service Email>@developer.gserviceaccount.com';
$key_file_location = '<keyName>.p12';
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array(Google_Service_Analytics::ANALYTICS),
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
'<My email>'
);
$client->getAuth()->setAssertionCredentials($cred);
$service = new Google_Service_Analytics($client);
$result = $service->management_profiles->listManagementProfiles('~all', '~all');
print_r($result);
listManagementProfiles 和 listManagementProfiles 两种方法都获取参数 $accountId 和 $webPropertyId 。
有人可以帮忙,为什么我在通过 API 获取自定义尺寸时出错?
查看文档 "~all"
是 specifically mentioned as valid parameter value for listManagementProfiles:
Account ID for the view (profiles) to retrieve. Can either be a
specific account ID or '~all', which refers to all the accounts to
which the user has access.
但不适用于 listManagementCustomDimensions,这里只是说
Account ID for the custom dimensions to retrieve.
(与 属性 id 相同)。因此,您的问题实际上就是错误消息所说的,查询自定义维度时不能使用 "~all"
。
因此,要列出所有自定义维度,您似乎必须遍历 属性 个 ID 列表(由 properties/list 方法返回),而不是使用 "~all".
好日子。当我尝试通过 API 获取自定义尺寸时,出现错误
Exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/customDimensions: (400) Cannot query by ~all for id webPropertyId'
我的代码
$service_account_name = '<Service Email>@developer.gserviceaccount.com';
$key_file_location = '<keyName>.p12';
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array(Google_Service_Analytics::ANALYTICS),
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
'<My email>'
);
$client->getAuth()->setAssertionCredentials($cred);
$service = new Google_Service_Analytics($client);
$result = $service->management_customDimensions->listManagementCustomDimensions('~all', '~all');
print_r($result);
获取目标的类似代码可以正常工作
$service_account_name = '<Service Email>@developer.gserviceaccount.com';
$key_file_location = '<keyName>.p12';
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array(Google_Service_Analytics::ANALYTICS),
$key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
'<My email>'
);
$client->getAuth()->setAssertionCredentials($cred);
$service = new Google_Service_Analytics($client);
$result = $service->management_profiles->listManagementProfiles('~all', '~all');
print_r($result);
listManagementProfiles 和 listManagementProfiles 两种方法都获取参数 $accountId 和 $webPropertyId 。 有人可以帮忙,为什么我在通过 API 获取自定义尺寸时出错?
查看文档 "~all"
是 specifically mentioned as valid parameter value for listManagementProfiles:
Account ID for the view (profiles) to retrieve. Can either be a specific account ID or '~all', which refers to all the accounts to which the user has access.
但不适用于 listManagementCustomDimensions,这里只是说
Account ID for the custom dimensions to retrieve.
(与 属性 id 相同)。因此,您的问题实际上就是错误消息所说的,查询自定义维度时不能使用 "~all"
。
因此,要列出所有自定义维度,您似乎必须遍历 属性 个 ID 列表(由 properties/list 方法返回),而不是使用 "~all".