public static IList<Activity> SearchActivitiesPaging(PlusService service, string _query, int NumberOfPages, int ItemsPerPage, string NextPageToken) { //List all of the activities in the specified collection for the current user. // Documentation: https://developers.google.com/+/api/latest/activities/list ActivitiesResource.SearchRequest list = service.Activities.Search(_query); int max = ItemsPerPage; int iterate = NumberOfPages; list.PageToken = NextPageToken; list.MaxResults = max; int count = 0; ActivityFeed activitesFeed = list.Execute(); IList<Activity> Activites = new List<Activity>(); count++; //// Loop through until we arrive at an empty page while (activitesFeed.Items != null || count <= iterate) { // Prepare the next page of results list.PageToken = activitesFeed.NextPageToken; // Adding each item to the list. foreach (Activity item in activitesFeed.Items) { Activites.Add(item); } // We will know we are on the last page when the next page token is // null. // If this is the case, break. if (activitesFeed.NextPageToken == null || count >= iterate) { break; } // Execute and process the next page request activitesFeed = list.Execute(); count++; } Activity token = new Activity(); token.Title = activitesFeed.NextPageToken; Activites.Add(token); return Activites; }
/// <summary> /// Search public activities. /// /// Documentation: https://developers.google.com/+/api/latest/activities/search /// </summary> /// <param name="service">a Valid authenticated PlusService</param> /// <param name="_query">Full-text search query string.</param> /// <returns></returns> public static IList<Activity> SearchActivities(PlusService service, string _query) { //List all of the activities in the specified collection for the current user. // Documentation: https://developers.google.com/+/api/latest/activities/list ActivitiesResource.SearchRequest list = service.Activities.Search(_query); list.MaxResults = 20; ActivityFeed activitesFeed = list.Execute(); IList<Activity> Activites = new List<Activity>(); int Count = 0; //// Loop through until we arrive at an empty page while (activitesFeed.Items != null) { // Adding each item to the list. foreach (Activity item in activitesFeed.Items) { Activites.Add(item); Count++; } // We will know we are on the last page when the next page token is // null. // If this is the case, break. if (activitesFeed.NextPageToken == null || Count > 300) { break; } // Prepare the next page of results list.PageToken = activitesFeed.NextPageToken; // Execute and process the next page request activitesFeed = list.Execute(); } return Activites; }