/// <summary> /// Search all public profiles. /// Documentation: https://developers.google.com/+/api/latest/people/search /// </summary> /// <param name="service"></param> /// <param name="_query">Specify a query string for full text search of public text in all profiles.</param> /// <returns></returns> public static IList <Person> SearchPeople(PlusService service, string _query) { PeopleResource.SearchRequest list = service.People.Search(_query); list.MaxResults = 50; PeopleFeed peopleFeed = list.Execute(); IList <Person> people = new List <Person>(); //// Loop through until we arrive at an empty page while (peopleFeed.Items != null) { // Adding each item to the list. foreach (Person item in peopleFeed.Items) { people.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 (peopleFeed.NextPageToken == null) { break; } // Prepare the next page of results list.PageToken = peopleFeed.NextPageToken; // Execute and process the next page request peopleFeed = list.Execute(); } return(people); }
public static IList<Person> SearchPeopleLimitedPaging(PlusService service, string _query, int NumberOfPages, int ItemsPerPage, string NextPageToken) { PeopleFeed peopleFeed = null; PeopleResource.SearchRequest list = service.People.Search(_query); int count = 0; int max = ItemsPerPage; int iterate = NumberOfPages; list.PageToken = NextPageToken; list.MaxResults = max; try { peopleFeed = list.Execute(); count++; } catch { } IList<Person> people = new List<Person>(); //// Loop through until we arrive at an empty page while (peopleFeed.Items != null || count < iterate) { // Prepare the next page of results list.PageToken = peopleFeed.NextPageToken; // Adding each item to the list. foreach (Person item in peopleFeed.Items) { people.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 (peopleFeed.NextPageToken == null || count >= iterate) { break; } // Execute and process the next page request peopleFeed = list.Execute(); count++; } Person token = new Person(); token.DisplayName = peopleFeed.NextPageToken; people.Add(token); return people; }