Пример #1
0
 public void EmptyQueryTest()
 {
     const string result = "http://www.test.com/";
     AccountQuery target = new AccountQuery();
     target.BaseAddress = result;
     Assert.AreEqual(new Uri(result), target.Uri);
 }
Пример #2
0
 public void UriTest()
 {
     AccountQuery target = new AccountQuery();
     Uri expected = new Uri("http://www.test.com/");
     Uri actual;
     target.Uri = expected;
     actual = target.Uri;
     Assert.AreEqual(expected, actual);
 }
Пример #3
0
 public void StartDateTest()
 {
     AccountQuery target = new AccountQuery();
     DateTime expected = DateTime.Now;
     DateTime actual;
     target.StartDate = expected;
     actual = target.StartDate;
     Assert.AreEqual(expected, actual);
 }
Пример #4
0
		public ReadOnlyCollection<DataFeed> GetDataFeeds()
		{
			var feedQuery = new AccountQuery("http://www.google.com/analytics/feeds/accounts/default");
			try
			{
				return _service.Query(feedQuery).Entries.Cast<AccountEntry>().Select(entry => new DataFeed(_service, entry.Title.Text, entry.ProfileId.Value)).ToList().AsReadOnly();
			}
			catch (GDataRequestException x)
			{
				throw new InvalidOperationException("Unable to log in.", x);
			}
		}
Пример #5
0
        public void QueryAccountIds()
        {
            AnalyticsService service = new AnalyticsService(this.ApplicationName);
            service.Credentials = new GDataCredentials(this.userName, this.passWord);

            AccountQuery feedQuery = new AccountQuery(AccountFeedUrl);
            AccountFeed actual = service.Query(feedQuery);

            foreach (AccountEntry entry in actual.Entries)
            {
                Assert.IsNotNull(entry.Id);
                Assert.IsNotNull(entry.ProfileId.Value);
                if (this.accountId == null)
                    this.accountId = entry.ProfileId.Value;
            }
        }
    /**
     * Creates a new service object, attempts to authorize using the Client Login
     * authorization mechanism and requests data from the Google Analytics API.
     * @throws AuthenticationException if an error occurs with authorizing with
     *     Google Accounts.
     * @throws IOException if a network error occurs.
     * @throws ServiceException if an error occurs with the Google Analytics API.
     */
    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();

      // Send our request to the Analytics API and wait for the results to
      // come back.
      accountFeed = asv.Query(query);
    }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            username = "******";
            password = "******";
            AccountsFeedUrl =
               "https://www.google.com/analytics/feeds/accounts/default";

            Service = new AnalyticsService("AnalyticsSampleApp");
            Service.setUserCredentials(username, password);

            AccountQuery AccountsQuery = new AccountQuery(AccountsFeedUrl);
            AccountFeed AccountsFeed = Service.Query(AccountsQuery);

            List<AtomEntry> Accounts = AccountsFeed.Entries.ToList();
            foreach (AtomEntry Account in Accounts)
                if (Account.Title.Text.Equals("www.sonetreach.com"))
                {
                    GetPageViews(Account);
                }
        }
Пример #8
0
        private void RefreshFeed()
        {
            string userName = this.Username.Text;
            string passWord = this.Password.Text;

            AccountQuery query = new AccountQuery();
            AnalyticsService service = new AnalyticsService("AnalyticsSampleApp");
            if (!string.IsNullOrEmpty(userName))
            {
                service.setUserCredentials(userName, passWord);
            }

            AccountFeed accountFeed = service.Query(query);
            foreach (AccountEntry entry in accountFeed.Entries)
            {
                ListViewItem item = new ListViewItem(entry.Title.Text);
                //item.SubItems.Add(entry.Title.Text);
                item.SubItems.Add(entry.ProfileId.Value);
                this.ProfileIds.Items.Add(item);
            }
        }
 /// <summary>
 /// overloaded to create typed version of Query
 /// </summary>
 /// <param name="feedQuery"></param>
 /// <returns>AccountFeed</returns>
 public AccountFeed Query(AccountQuery feedQuery) {
     return base.Query(feedQuery) as AccountFeed;
 }
Пример #10
0
 public void ExtraParametersTest()
 {
     AccountQuery target = new AccountQuery();
     string expected = "TestValue";
     string actual;
     target.ExtraParameters = expected;
     actual = target.ExtraParameters;
     Assert.AreEqual(expected, actual);
 }
Пример #11
0
        static void Main(string[] args)
        {
            //test limiter
            //TestLimiter();

            //initialize a new limiter with 10 concurrent and 10 requests per second.
            Limiter limiter = new Limiter(TimeSpan.FromSeconds(1), 10, 10);

            string username = "******";
            string password = "******";

            //first, initialize a service, its the query provider.
            var service = new Google.GData.Analytics.AnalyticsService("AnalyticsReader");

            //you can also use service.setUserCredentials(username,password)
            service.Credentials = new Google.GData.Client.GDataCredentials(username, password);

            //first, query for all accounts
            var accountquery = new Google.GData.Analytics.AccountQuery();

            accountquery.NumberToRetrieve = 10000; //Maximum

            limiter.Enter();
            var accountresult = service.Query(accountquery);

            limiter.Exit();

            //for each account, retrieve records
            foreach (AccountEntry account in accountresult.Entries)
            {
                //get the timezone for the account, as all data is saved based on that timezone.
                Property timezone = account.Properties.Where(i => i.Name == "ga:timezone").FirstOrDefault();


                Console.WriteLine(
                    "\nProfile Title     = " + account.Title.Text +
                    "\nProfile ID        = " + account.ProfileId.Value +
                    "\nTimeZone       = " + timezone.Value);

                TzTimeZone tzinfo = null;

                if (timezone != null)
                {
                    tzinfo = TzTimeZone.GetTimeZone(timezone.Value);
                }

                //retrieve analytics data
                DataQuery query = new DataQuery();
                query.Ids = account.ProfileId.Value;

                //Data

                //dimensions are the "group by"
                query.Dimensions = "ga:date,ga:hour,ga:hostname,ga:country,ga:keyword,ga:source,ga:referralPath";

                //metrics are the values
                query.Metrics = "ga:bounces,ga:newVisits,ga:pageviews,ga:timeOnSite,ga:visits";

                //start from yesterday
                query.GAStartDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");

                //until today
                query.GAEndDate  = DateTime.Now.ToString("yyyy-MM-dd");
                query.StartIndex = 1;

                //Maximum allowed by Quota.
                query.NumberToRetrieve = 10000;


                limiter.Enter();
                DataFeed dataFeedVisits = service.Query(query);
                limiter.Exit();

                //process each record returned
                foreach (DataEntry dentry in dataFeedVisits.Entries)
                {
                    var line = new Dictionary <string, string>();

                    //insert into directory for each processing
                    for (int i = 0; i < dentry.Metrics.Count; i++)
                    {
                        line[dentry.Metrics[i].Name] = dentry.Metrics[i].Value;
                    }

                    for (int i = 0; i < dentry.Dimensions.Count; i++)
                    {
                        line[dentry.Dimensions[i].Name] = dentry.Dimensions[i].Value;
                    }

                    //get the UTC datetime from the ga:date + ga:hour + profile timezone combination
                    DateTime date = DateTime.ParseExact(line["ga:date"], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
                    int      hour = Convert.ToInt32(line["ga:hour"]);
                    date = date.AddHours(hour);

                    line["dateutc"] = ConvertToUtc(date, tzinfo).ToString();


                    //dump to console all data found
                    Console.Write("UTC: {0}, ", line["dateutc"]);

                    for (int i = 0; i < dentry.Dimensions.Count; i++)
                    {
                        Console.Write("{0}: {1}, ", dentry.Dimensions[i].Name, dentry.Dimensions[i].Value);
                    }

                    for (int i = 0; i < dentry.Metrics.Count; i++)
                    {
                        Console.Write("{0}: {1}, ", dentry.Metrics[i].Name, dentry.Metrics[i].Value);
                    }

                    Console.WriteLine();
                }
            }
        }
Пример #12
0
 public void QueryTest()
 {
     AccountQuery target = new AccountQuery();
     string expected = "TestValue";
     string actual;
     target.Query = expected;
     actual = target.Query;
     Assert.AreEqual(expected, actual);
 }
Пример #13
0
        static void Main(string[] args)
        {
            //test limiter
            //TestLimiter();

            //initialize a new limiter with 10 concurrent and 10 requests per second.
            Limiter limiter = new Limiter(TimeSpan.FromSeconds(1), 10, 10);

            string username = "******";
            string password = "******";

            //first, initialize a service, its the query provider.
            var service = new Google.GData.Analytics.AnalyticsService("AnalyticsReader");

            //you can also use service.setUserCredentials(username,password)
            service.Credentials = new Google.GData.Client.GDataCredentials(username, password);

            //first, query for all accounts
            var accountquery = new Google.GData.Analytics.AccountQuery();

            accountquery.NumberToRetrieve = 10000; //Maximum

            limiter.Enter();
            var accountresult = service.Query(accountquery);
            limiter.Exit();

            //for each account, retrieve records
            foreach (AccountEntry account in accountresult.Entries)
            {
                //get the timezone for the account, as all data is saved based on that timezone.
                Property timezone = account.Properties.Where(i => i.Name == "ga:timezone").FirstOrDefault();


                Console.WriteLine(
                  "\nProfile Title     = " + account.Title.Text +
                  "\nProfile ID        = " + account.ProfileId.Value + 
                  "\nTimeZone       = " + timezone.Value);

                TzTimeZone tzinfo = null;

                if (timezone != null)
                    tzinfo = TzTimeZone.GetTimeZone(timezone.Value);

                //retrieve analytics data
                DataQuery query = new DataQuery();
                query.Ids = account.ProfileId.Value;

                //Data

                //dimensions are the "group by"
                query.Dimensions = "ga:date,ga:hour,ga:hostname,ga:country,ga:keyword,ga:source,ga:referralPath";

                //metrics are the values
                query.Metrics = "ga:bounces,ga:newVisits,ga:pageviews,ga:timeOnSite,ga:visits";
                
                //start from yesterday
                query.GAStartDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");

                //until today
                query.GAEndDate = DateTime.Now.ToString("yyyy-MM-dd");
                query.StartIndex = 1;

                //Maximum allowed by Quota.
                query.NumberToRetrieve = 10000;


                limiter.Enter();
                DataFeed dataFeedVisits = service.Query(query);
                limiter.Exit();

                //process each record returned
                foreach (DataEntry dentry in dataFeedVisits.Entries)
                {
                    var line = new Dictionary<string, string>();

                    //insert into directory for each processing
                    for (int i = 0; i < dentry.Metrics.Count; i++)
                        line[dentry.Metrics[i].Name] = dentry.Metrics[i].Value;

                    for (int i = 0; i < dentry.Dimensions.Count; i++)
                        line[dentry.Dimensions[i].Name] = dentry.Dimensions[i].Value;

                    //get the UTC datetime from the ga:date + ga:hour + profile timezone combination
                    DateTime date = DateTime.ParseExact(line["ga:date"], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
                    int hour = Convert.ToInt32(line["ga:hour"]);
                    date = date.AddHours(hour);

                    line["dateutc"] = ConvertToUtc(date, tzinfo).ToString();


                    //dump to console all data found
                    Console.Write("UTC: {0}, ", line["dateutc"]);

                    for (int i = 0; i < dentry.Dimensions.Count; i++)
                        Console.Write("{0}: {1}, ", dentry.Dimensions[i].Name, dentry.Dimensions[i].Value);

                    for (int i = 0; i < dentry.Metrics.Count; i++)
                        Console.Write("{0}: {1}, ", dentry.Metrics[i].Name, dentry.Metrics[i].Value);

                    Console.WriteLine();

                }

            }

        }
 /// <summary>
 /// overloaded to create typed version of Query
 /// </summary>
 /// <param name="feedQuery"></param>
 /// <returns>AccountFeed</returns>
 public AccountFeed Query(AccountQuery feedQuery)
 {
     return(base.Query(feedQuery) as AccountFeed);
 }
Пример #15
0
 public void AccountQueryConstructorTest()
 {
     const string baseUri = "http://www.test.com/";
     AccountQuery target = new AccountQuery(baseUri);
     Assert.AreEqual(target.Uri, new Uri(baseUri));
 }
Пример #16
0
 public void AccountQueryConstructorTest1()
 {
     AccountQuery target = new AccountQuery();
     Assert.IsNotNull(target);
 }
Пример #17
0
 public void NumberToRetrieveTest()
 {
     AccountQuery target = new AccountQuery();
     int expected = 12;
     int actual;
     target.NumberToRetrieve = expected;
     actual = target.NumberToRetrieve;
     Assert.AreEqual(expected, actual);
 }