2014-02-27 50 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。 –