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

相關問題