/// <summary> /// Lists web properties to which the user has access for a given account /// Documentation: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/list /// </summary> /// <param name="service">Valid authenticated Analytics Service</param> /// <param name="accountId">Account Id </param> /// <returns>A Web property resource https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties </returns> public static IList <Webproperty> WebpropertyList(AnalyticsService service, string accountId) { ManagementResource.WebpropertiesResource.ListRequest list = service.Management.Webproperties.List(accountId); list.MaxResults = 1000; Webproperties feed = list.Execute(); List <Webproperty> returnList = new List <Webproperty>(); //// Loop through until we arrive at an empty page while (feed.Items != null) { // Adding items to the list returnList.AddRange(feed.Items); // We will know we are on the last page when the next page token is // null. // If this is the case, break. if (feed.NextLink == null) { break; } // Prepare the next page of results list.StartIndex = feed.StartIndex + list.MaxResults; // Execute and process the next page request feed = list.Execute(); } return(returnList); }
/// <summary> /// retrieves a list of the Google Analtyics accounts for the curently autenticated user. /// </summary> /// <param name="service">AnalyticsService</param> /// <param name="pAccount">The account we would like to request propertys for</param> /// <returns></returns> public static Webproperties Propertieslist(AnalyticsService service, string pAccount) { ManagementResource.WebpropertiesResource.ListRequest request = service.Management.Webproperties.List(pAccount); try { Webproperties result = request.Execute(); return(result); } catch (Exception) { return(null); } }
public static void readAction(GAAutentication Autentication, string Action) { string[] vars = Action.Split(' '); switch (vars[0].ToLower()) { case "menu": Program.ListMenu(Autentication); break; case "accounts": Console.WriteLine(""); Console.WriteLine("Listing Accounts: "); Accounts myAccounts = GAManagement.Accountlist(Autentication.service); if (myAccounts == null) { Console.WriteLine("User does not have access to any Accounts"); } else { foreach (Account accnt in myAccounts.Items) { Console.WriteLine(accnt.Name + " - " + accnt.Id); } } Program.PromptDoNext(Autentication); break; case "segments": Console.WriteLine(""); Console.WriteLine("Listing Segments: "); Segments mySegments = GAManagement.SegmentList(Autentication.service); foreach (Segment sgmnt in mySegments.Items) { Console.WriteLine(sgmnt.Name + " - " + sgmnt.SegmentId); } Program.PromptDoNext(Autentication); break; case "wp": if (vars.Count() < 2) { Console.WriteLine("ERROR: WebProperty list requires an account id: " + vars[0]); Console.ReadLine(); } else { Console.WriteLine(""); Console.WriteLine("Listing WebProperties for account: " + vars[1]); Webproperties myWebproperties = GAManagement.Propertieslist(Autentication.service, vars[1]); if (myWebproperties == null) { Console.WriteLine("User does not have access to any Web Properties for:"); Console.WriteLine(" Account id: " + vars[1]); } else { foreach (Webproperty wbprprty in myWebproperties.Items) { Console.WriteLine(wbprprty.Name + " - " + wbprprty.Id); } } Program.PromptDoNext(Autentication); } break; case "views": if (vars.Count() < 3) { Console.WriteLine("ERROR: View list requires an account id, and a webproperty id: "); Program.PromptDoNext(Autentication); } else { Console.WriteLine(""); Console.WriteLine("Listing WebProperties for account: " + vars[1]); Profiles myViews = GAManagement.ProfilesList(Autentication.service, vars[1], vars[2]); if (myViews == null) { Console.WriteLine("User does not have access to any Views for:"); Console.WriteLine(" Account id: " + vars[1]); Console.WriteLine(" Web Property id: " + vars[2]); } else { foreach (Profile vws in myViews.Items) { Console.WriteLine(vws.Name + " - " + vws.Id); } } Program.PromptDoNext(Autentication); } break; case "goals": if (vars.Count() < 4) { Console.WriteLine("ERROR: Goal list requires an account id, webproperty id, and a profileid: "); Program.PromptDoNext(Autentication); } else { Console.WriteLine(""); Console.WriteLine("Listing Goals for account: " + vars[1]); Goals myGoals = GAManagement.GoalList(Autentication.service, vars[1], vars[2], vars[3]); if (myGoals.Items == null) { Console.WriteLine("User does not have access to any Goals for:"); Console.WriteLine(" Account id: " + vars[1]); Console.WriteLine(" Web Property id: " + vars[2]); Console.WriteLine(" Profile id: " + vars[3]); } else { foreach (Goal gl in myGoals.Items) { Console.WriteLine(gl.Name + " - " + gl.Id); } } Program.PromptDoNext(Autentication); } break; case "summary": Console.WriteLine(""); Console.WriteLine("Listing Account Summary: "); AccountSummaries mySummary = GAManagement.AccountSummaryList(Autentication.service); if (mySummary == null) { Console.WriteLine("User does not have access to any Accounts"); } else { foreach (AccountSummary sum in mySummary.Items) { Console.WriteLine("Account name: " + sum.Name + " - " + sum.Id); foreach (WebPropertySummary wpsum in sum.WebProperties) { Console.WriteLine(" Web Property: " + wpsum.Name + " - " + wpsum.Id); if (wpsum.Profiles != null) { foreach (ProfileSummary pfsum in wpsum.Profiles) { Console.WriteLine(" Profiles: " + pfsum.Name + " - " + pfsum.Id); } } else { Console.WriteLine(" No Profiles"); } } } } Program.PromptDoNext(Autentication); break; default: Console.WriteLine("unknown option: " + vars[0]); Program.PromptDoNext(Autentication); break; } }