2014-02-27 46 views
1

嘗試從C#中的Google Analytics API測試此帳戶供稿。AccountFeed返回null,GA API

無論如何,這裏是代碼示例,由於某些原因,accountFeed保留爲空,即使我提供帳戶信息。不知道這是否是版本問題。

public AccountFeedExample() 
    { 

     // Configure GA API. 
     AnalyticsService asv = new AnalyticsService("gaExportAPI_acctSample_v2.0"); 

     // Client Login Authorization. 
     asv.setUserCredentials(CLIENT_USERNAME, CLIENT_PASS); 

     // GA Account Feed query uri. 

     AccountQuery query = new AccountQuery("https://www.googleapis.com/analytics/v2.4/management/accounts"); 

//Tried to manually insert the date info, still shows the accountfeed as null. 
     query.StartDate = new DateTime(2014, 1, 1); 
     query.EndDate = new DateTime(2014, 1, 14); 

     // Send our request to the Analytics API and wait for the results to 
     // come back. 
     accountFeed = asv.Query(query); 
    } 

試圖將它在這個格式重新寫: http://www.googleapis.com/analytics/v2.4/management/accounts/1234/webproperties/UA-1234-2/profiles

從以下鏈接: https://developers.google.com/analytics/devguides/config/mgmt/v2/mgmtFeedReference#accountFeed

似乎不工作,不知道我錯過了什麼。

回答

1

你錯過了認證過程。您需要先登錄Oauth2才能訪問任何內容。第二個問題是Management API用於返回有關帳戶的信息並且不需要日期。實際返回數據並需要日期的core reporting API

首先,你應該使用V3客戶端庫而不是V2,而V3可能仍然處於測試階段,使用起來很麻煩。您需要的庫的金塊命令是:

pm>Install-Package Google.Apis.Analytics.v3 -Pre 

我能走動的你,儘管如何訪問Google Analtyics with C#的教程。

讓我知道,如果我可以有任何幫助。

+0

只是通過您的教程,它正是我所需要的,我也得到了nuget安裝。謝謝,給你檢查和嘖嘖的+1。 –