1

Goog日。当我尝试通过API来获取自定义维度,我得到了错误通过Google Analytics(分析)API获取自定义维度时的问题

异常 'Google_Service_Exception' 有消息 '错误调用get https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/customDimensions: (400)无法通过查询〜所有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获取自定义维度?

+0

的注释为他人调用'listManagementProfiles'与'〜all'参数,如果您想要所有帐户,属性和视图的列表,请致电[帐户摘要](https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accountSummaries/list)端点。 – Matt

回答

1

综观文档"~all"specifically mentioned as valid parameter value for listManagementProfiles

为视图(配置文件)的帐户ID来检索。可以是 特定帐户ID或'〜all',它指的是用户有权访问的所有帐户为 。

而不是listManagementCustomDimensions,这里是说,自定义尺寸只是

帐户ID检索。

(属性id相同)。因此,您的问题实际上是错误消息所说的,您在查询自定义维度时不能使用"~all"

如此看来,列出所有的自定义维度你必须通过属性id的列表(由properties/list方法返回)进行迭代,而不是使用"~all".

+0

谢谢,它工作正常,当我调用propertyID的方法。 – andynador

相关问题