2015-04-07 200 views
3

我試圖通過OAuth2訪問Google Analytics API。Google Analytics API - 與Symfony2集成

我所做的:

  1. 開放開發控制檯> API和驗證>憑據

  2. 創建一個新的客戶端ID

  3. 生成P12關鍵

  4. 複製的關鍵在服務器上

  5. 打開谷歌分析頁>管理員>帳戶>用戶管理

  6. 從生成的客戶端ID添加電子郵件,是這樣的:[email protected]

  7. 提供此電子郵件閱讀和分析權限

  8. 然後當我回到開發者控制檯>權限。新的電子郵件在服務中添加賬戶的編輯權限

  9. 重新檢查,如果谷歌Analytics(分析)已啓用,並且數據將會英寸

現在我已經安裝了widop /谷歌分析束和配置包:

widop_google_analytics: 
    client_id:  "[email protected]" 
    profile_id:  "ga:12345678" 
    private_key_file: "mykey.p12" 
    http_adapter:  "widop_http_adapter.curl" 

我嘗試創建查詢:

 $profileId = 'ga:12345678'; 
     $query = new Query($profileId); 

     $query->setStartDate(new \DateTime('-2months')); 
     $query->setEndDate(new \DateTime()); 

     $query->setMetrics(array('ga:visits' ,'ga:bounces')); 
     $query->setDimensions(array('ga:browser', 'ga:city')); 

     $query->setSorts(array('ga:country', 'ga:browser')); 

     $query->setFilters(array('ga:browser=~^Firefox')); 

     $query->setSegment('gaid::10'); 

     $query->setStartIndex(1); 
     $query->setMaxResults(10000); 
     $query->setPrettyPrint(false); 
     $query->setCallback(null); 

     $clientId = '[email protected]'; 
     $privateKeyFile = 'mykey.p12'; 
     $httpAdapter = new CurlHttpAdapter(); 

     $client = new Client($clientId, $privateKeyFile, $httpAdapter); 
     $token = $client->getAccessToken(); 

     $service = new Service($client); 
     $response = $service->query($query); 

     return $response; 

作爲迴應,我得到這個錯誤:

User does not have sufficient permissions for this profile. 

當我打開開發者控制檯>概述> 1小時(標籤)

我不得不通知,要求要在

從一切 - 我認爲驗證和查詢是好的,但用戶沒有權限獲取任何類型的數據,這是奇怪的,因爲我已經授予了讀取和分析權限 [email protected]

Wha t可以通過這種例外的原因嗎?

回答

1

我不知道你是否已經解決了這個問題。 我的解決方案是在分析帳戶上使用視圖ID而不是帳戶ID。 視圖ID位於Google Analytics管理面板上設置的第三列。

對不起,我的英語。