Beispiel #1
0
        /// <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);
            }
        }