Paging through results

Sep 16, 2008 at 6:08 AM
Thanks for putting this together.

Question - I cant seem to page through results or call any results starting from anywhere but page 1.  Am I missing something?

Also, was getting some strange errors on some of the search types other than web.  Are ones like Video not yet implemented?


Sep 16, 2008 at 6:43 AM
Everything should work.

Could you post your code (short example please...)?
Sep 17, 2008 at 2:12 AM
SearchResults searchResults = Searcher.Search(SearchType.Web, "some%20search%20term", 0);

            foreach (SearchResult result in searchResults.Items)
                Label1.Text += "<a href='" + result.Url + "'>" + result.Title + "<a/><br/>";
                Label1.Text += "<font color='#666666'>" + result.Content + "</font><br/><br/>";

// ------------------------------------------------------------------------------------------

That will return the first set of results. 

If I change the the pageIndex to anything other than 0, it makes no difference.

I'm trying to get it so I can loop through all results on every page. (up to a certain pooint I suppose.  Say 100).

Thanks for your quick reply!

Sep 17, 2008 at 5:02 AM
1. The search string should be in plain text, not HTML encoded (i.e. don't put %20, but space). If you get this string from a web request, just do HttpUtility.HtmlDecode().

2. You can't use any page you want. The SearchResults object has a property called 'Pages' which lists the pages you can use (it will change for every request representing forward & backward pages).

Note: Google limits the number of answers for every request to 8, that's why the number of answer in every request is so small.
Sep 17, 2008 at 5:42 AM
1. Ok, good to know

2. Apologies if I'm missing something straight forward.  How should I be calling up the next set of 8 records?
Sep 17, 2008 at 5:47 AM
Usually the pages are: 0, 8, 16, ... (unless those pages simply does not exist).
So to call the second page you should pass 8.

Anyhow the 'Pages' property contains the list of valid page numbers.
Sep 18, 2008 at 2:23 AM


searchResults = Searcher.Search(SearchType.Web, "olympics", 0);




searchResults = Searcher.Search(SearchType.Web, "olympics", 8);

returns the same set of results.




searchResults = Searcher.Search(SearchType.Local, "olympics");

Returns: "Could not find key: 'cursor' in JSON object " (Exception Details: Gapi.Json.JsonException: Could not find key: 'cursor' in JSON object)

Shouldn't I have to set the location ('near') somewhere?


Sep 24, 2008 at 10:53 AM
Same as localman - I supply the next page based on the Pages[] returned.
_pageIndex is always 0

Fantastic job btw - very clean.
Oct 15, 2008 at 2:37 PM
That's it?
No way?
Oct 18, 2008 at 7:10 AM
Sorry for the detailed response.

As for paging - you're right - I've fixed it in version 0.2.3

Local search - it seems there are few problems with the local search - setting the local position & getting the results. The results of each search type are a bit different. I tried to use the local common features but it seems that's not enough. To be continued...
Oct 21, 2008 at 3:59 PM
First of all thank you for supplying this tool. However, I am getting the same behavior in version 0.2.3. It seems to stay stuck on the Page Index of [0]. Is there any way around this?
Oct 21, 2008 at 4:08 PM
Can you post your code (short example please...)?
Oct 21, 2008 at 4:09 PM
        Gapi.Search.SearchResults searchResults =  Gapi.Search.Searcher.Search(Gapi.Search.SearchType.Web,"NBA",16);

Oct 21, 2008 at 4:17 PM
Worked just fine for me. Maybe you got the old DLL cached somewhere?

Here are the results I got:
URLs for results on page 0:

URLs for results on page 16:
Press any key to continue . . .
Oct 21, 2008 at 5:53 PM
And so you are correct. Thank you. After a second look I noticed that even though in the locals window of VS it appears to always be at [0], the results are indeed different. Moving on, is it not possible to implement a custom search ID from google and use the "setSiteRestriction" method or use  the "cx?" argument? Basically, can you use google custom search?
Oct 21, 2008 at 6:44 PM
I don't think the Ajax API support this option.
You can check the documentation of the API I'm using:

If you'll find anything I'll be more than happy to add it.
Oct 21, 2008 at 7:03 PM
Thanks for the fast reply. The Ajax API does indeed support these options.
Here are some links:
Google web search:

Argument ref:

general API listing:

Thanks again!

Oct 22, 2008 at 10:23 AM
I've added the search options to the API (there's now 2 new prototypes of "Search" function which allows using the various arguments).
Now the Local search works too.
Nov 2, 2008 at 4:45 PM
First of all, thanks for the code. Its a big relief to work server-side with google.

What I want to know is how to get rid of the error "Could not find key: 'pages' in JSON object" if there are no results to show.

It seems as if google finds no results, this error comes up. Is there a way to catch it?


(Gapi.Search.Searcher.Search(SearchType.Web, searchString,0).EstimatedResultCount > 0)



...doesn't work: He trows an error since the error happens somewhere in JSON class.

Thanks in advance.
Nov 2, 2008 at 6:26 PM
I've just uploaded a new version which doesn't throw an exception if the Search API returns no result.
Nov 10, 2008 at 7:52 AM

Whenever I try to retrieve over 64 results, i get the following error message, even though the queries i try has more than 64 results.

ResponseStatus: 400, Reason: out of range start, Response data: {"responseData": null, "responseDetails": "out of range start", "responseStatus": 400}

Any ideas would be greatly appreciated

Nov 10, 2008 at 10:33 AM
Google AJAX Search API does not allow more than 64 results (e.g. max page is 56).

You should limit you pages to those in the "Pages" property of the results object.
Mar 7, 2009 at 12:12 PM
Edited Mar 7, 2009 at 12:43 PM
First ... many thanx for this project. Very usefull!!
However, got a strange problem.
I'm searching like the example of localman.


searchResults = Searcher.Search(SearchType.Web, "suzuki", 0);


searchResults = Searcher.Search(SearchType.Web, "suzuki", 8);

The pageIndex I use, comes from the Pages[].
The good news is: The search results provided by Google are indeed 2 different resultsets. Just as expected!
The bad news is, searchResults.CurrentPageIndex stays 0, and the contents of searchResults.Pages[] doesn't change either ...

Any ideas?
Apr 3, 2009 at 12:49 PM
Hello All,
with regards to Google Ajax api searchresult, especially the amount: Is that really all???

I found a workaround, but i think it a bit silly to restrict a platform where people experiment with the possibilities of your service. Anyway, maybe this is old news, but the answer is: forget ajax, and dig through the other types of output. result at: ; a bit slow; have to tweak loading/building sequence, since its loadin 180 images....

results via proxy; return page contains javascript object with results that you can use; with a bit of effort

It works, but i have a feeling that it could be more efficient

Apr 7, 2010 at 8:20 PM
shporer wrote:
You should limit you pages to those in the "Pages" property of the results object.



Can you tell me, how to do this?


I can't find any option to set the page limit :-(