Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle c# Api, changing from v2.3 to v3
    text
    copied!<p>I have the following code to query google analytics using the C# v2.3 api:</p> <pre><code>string username = "SAMPLE@SAMPLE.COM"; string pass = "PASS"; string gkey = "?key=XXXXXXXXXXXXXXXXXXXXXXXXXXX"; string dataFeedUrl = "https://www.google.com/analytics/feeds/data" + gkey; AnalyticsService service = new AnalyticsService("API Sample"); service.setUserCredentials(username, pass); DataQuery query1 = new DataQuery(dataFeedUrl); query1.Ids = "ga:34197921"; query1.Dimensions = "ga:medium,ga:campaign,ga:date,ga:isMobile,ga:isTablet,ga:searchKeyword,ga:hostname"; query1.Metrics = "ga:visits,ga:visitors,ga:visitBounceRate,ga:goalStartsAll,ga:goalCompletionsAll,ga:goal1Starts,ga:goal1Completions,ga:goal2Starts,ga:goal2Completions,ga:goal3Starts,ga:goal3Completions,ga:goal4Starts,ga:goal4Completions,ga:adCost,ga:totalValue"; query1.Sort = "ga:date,ga:hour"; query1.NumberToRetrieve = 50; query1.GAStartDate = new DateTime(2012, 1, 2).ToString("yyyy-MM-dd"); query1.GAEndDate = DateTime.Now.ToString("yyyy-MM-dd"); query1.StartIndex = 1; DataFeed dataFeedVisits = service.Query(query1); foreach (DataEntry entry in dataFeedVisits.Entries) { .... } </code></pre> <p>I would like to upgrade the newer v3 api but find it difficult to see any simple examples online where someone authenticates using the google oAuth and then queries the google analytics data.</p> <p>I install the following NuGet package: Install-Package Google.Apis.Analytics.v3 -Pre In a new c# solution, it gives me the following additional references: </p> <ul> <li>Google.Apis </li> <li>Google.Apis.Analytics.v3 </li> <li>Google.Apis.Auth</li> <li>Google.Apis.Auth.PlatformServices </li> <li>Google.Apis.PlatformServices</li> <li>log4net </li> <li>Newtownsoft.Json </li> <li>Zlib.Portable</li> </ul> <p>I have seen this article, which seems to run a similar piece of code to what I need to run: <a href="https://stackoverflow.com/questions/10752697/how-to-send-google-analytic-report-query-using-asp-net-google-analytic-api-versi">How to send Google analytic report query using ASP.net Google analytic api Version 3(Google.Apis.Analytics.v3.dll)?</a></p> <p>However, none of the code in this article resolves using the google libraries that where referenced in the NuGet.</p> <p>What am I missing and how can I complete the picture. How do I authenticate and the run my query to google analytics. </p> <p>Thumbs down to google for not having an easy to follow tutorial online to support their .net library!</p> <p>Thanks in advance for any advice!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload