문제

trying to test out this account feed from Google Analytics API in C#.

anyway, here is the code example, for some reason, the accountFeed stays null, even though I provide the account information. Not sure if this is a version problem.

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);
    }

Tried to re-write it in this format: http://www.googleapis.com/analytics/v2.4/management/accounts/1234/webproperties/UA-1234-2/profiles

from the following link: https://developers.google.com/analytics/devguides/config/mgmt/v2/mgmtFeedReference#accountFeed

doesn't seem to work, not sure what I am missing.

도움이 되었습니까?

해결책

Your missing the hole authentication process in that. You need to log with Oauth2 before you can to access anything. Second problem is that the Management API is for returning information about the accounts and doesn't require dates. The core reporting API that actually returns the data and requires dates.

Foremost you should be using the V3 client lib not V2, while V3 might still be in beta its a lot easer to use. The nugget command for the libs you need is:

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

I have a tutorial that walks you though how to access Google Analtyics with C#.

Let me know if I can be of any more help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top