Quasense Posted February 12, 2015 Share Posted February 12, 2015 hi , I wrote this code with C # And 50 of Google's search results will show c# code GwebSearchClient client = new GwebSearchClient("WWW.blogfa.com"); IList<IWebResult> results = client.Search(" Test ", 50); // foreach (IWebResult result in results) { listBox1.Items.Add(result.VisibleUrl); } The PHP code is the same as C # code ,But why only 4 examples displays?What changes should I do in the PHP code? php code <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php /** * google_search_api() * Query Google AJAX Search API * * @param array $args URL arguments. For most endpoints only "q" (query) is required. * @param string $referer Referer to use in the HTTP header (must be valid). * @param string $endpoint API endpoint. Defaults to 'web' (web search). * @return object or NULL on failure */ function google_search_api($args, $referer = 'http://localhost/test/', $endpoint = 'web'){ $url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint; if ( !array_key_exists('v', $args) ) $args['v'] = '1.0'; $url .= '?'.http_build_query($args, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // note that the referer *must* be set curl_setopt($ch, CURLOPT_REFERER, $referer); $body = curl_exec($ch); curl_close($ch); //decode and return the response return json_decode($body); } $rez = google_search_api(array( 'q' => 'Test', )); //results[$x]->url; print_r($rez); ?> Quote Link to comment https://forums.phpfreaks.com/topic/294556-getting-more-than-4-results-google-search/ Share on other sites More sharing options...
Solution QuickOldCar Posted February 12, 2015 Solution Share Posted February 12, 2015 (edited) Modify this area to add the start and rsz to the url as well if ( !array_key_exists('v', $args) ){ $args['v'] = '1.0'; } if ( !array_key_exists('start', $args) ){ $args['start'] = '0'; } if ( !array_key_exists('rsz', $args) ){ $args['rsz'] = '8'; } You will see that it only supports up to 8 results now so must loop through all the start rows http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=test&start=0&rsz=8 http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=test&start=8&rsz=8 http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=test&start=16&rsz=8 I believe their feed still accepts more parameters Results: Array( [responseData] => Array ( [results] => Array ( [0] => Array ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.speedtest.net/ => http://www.speedtest.net/ [visibleUrl] => www.speedtest.net [cacheUrl] => http://www.google.com/search?q=cache:M47_v0xF3m8J:www.speedtest.net [title] => Speedtest.net by Ookla - The Global Broadband Speed Test [titleNoFormatting] => Speedtest.net by Ookla - The Global Broadband Speed Test [content] => Bandwidth test where one can choose among hundreds of geographicallydispersed servers around the world. Also shows a summary of one's tests andalso ... ) [1] => Array ( [GsearchResultClass] => GwebSearch [unescapedUrl] => https://www.test.com/ => https://www.test.com/ [visibleUrl] => www.test.com [cacheUrl] => http://www.google.com/search?q=cache:S92tylTr1V8J:www.test.com [title] => Create Tests for Organizational Training and Certification Programs ... [titleNoFormatting] => Create Tests for Organizational Training and Certification Programs ... [content] => Test.com provides a complete software solution for creating online tests andmanaging enterprise and specialist certification programs, in up to 22 languages. ) [2] => Array ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.humanmetrics.com/cgi-win/jtypes2.asp => http://www.humanmetrics.com/cgi-win/jtypes2.asp [visibleUrl] => www.humanmetrics.com [cacheUrl] => http://www.google.com/search?q=cache:w_lAt3mgXcoJ:www.humanmetrics.com [title] => Personality test based on C. Jung and I. Briggs Myers type theory [titleNoFormatting] => Personality test based on C. Jung and I. Briggs Myers type theory [content] => This free test is based on Carl Jung's and Isabel Briggs Myers' typological ... theresults of this test as an input into the Jung Marriage Test™ and the Demo of the... ) [3] => Array ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.tested.com/ => http://www.tested.com/ [visibleUrl] => www.tested.com [cacheUrl] => http://www.google.com/search?q=cache:rBdvHZdNCuoJ:www.tested.com [title] => Tested [titleNoFormatting] => Tested [content] => 1 day ago ... (This video was brought to you by Premium memberships on Tested. Learn moreabout how you can support us by joining the Tested Premium ... ) [4] => Array ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.speakeasy.net/speedtest/ => http://www.speakeasy.net/speedtest/ [visibleUrl] => www.speakeasy.net [cacheUrl] => http://www.google.com/search?q=cache:71lCly1h_zMJ:www.speakeasy.net [title] => Speakeasy Speed Test - Powered by MegaPath [titleNoFormatting] => Speakeasy Speed Test - Powered by MegaPath [content] => ... data and IT solutions. We ensure the speed, performance and reliability of allour services by managing our own nationwide private network. Test Availability ... ) [5] => Array ( [GsearchResultClass] => GwebSearch [unescapedUrl] => https://implicit.harvard.edu/implicit/takeatest.html => https://implicit.harvard.edu/implicit/takeatest.html [visibleUrl] => implicit.harvard.edu [cacheUrl] => http://www.google.com/search?q=cache:hp0jVrH5XiUJ:implicit.harvard.edu [title] => Take a Test - Harvard University [titleNoFormatting] => Take a Test - Harvard University [content] => Preliminary Information. Whichever IAT you do, we will ask you (optionally) toreport your attitudes toward or beliefs about these topics, and provide some ... ) [6] => Array ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.16personalities.com/free-personality-test => http://www.16personalities.com/free-personality-test [visibleUrl] => www.16personalities.com [cacheUrl] => http://www.google.com/search?q=cache:4LI399t6RKYJ:www.16personalities.com [title] => Free personality test | 16Personalities [titleNoFormatting] => Free personality test | 16Personalities [content] => Free personality test. Three things to know before taking the test: Takes less than12 minutes. Answer honestly (even if you don't like the answer). Try not to ... ) [7] => Array ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://en.wikipedia.org/wiki/Test_cricket => http://en.wikipedia.org/wiki/Test_cricket [visibleUrl] => en.wikipedia.org [cacheUrl] => http://www.google.com/search?q=cache:q9anJ7AXMjMJ:en.wikipedia.org [title] => Test cricket - Wikipedia, the free encyclopedia [titleNoFormatting] => Test cricket - Wikipedia, the free encyclopedia [content] => Test cricket is the longest form of the sport of cricket. Test matches are playedbetween national representative teams with "Test status", as determined by the ... ) ) [cursor] => Array ( [resultCount] => 239,000,000 [pages] => Array ( [0] => Array ( [start] => 0 [label] => 1 ) [1] => Array ( [start] => 8 [label] => 2 ) [2] => Array ( [start] => 16 [label] => 3 ) [3] => Array ( [start] => 24 [label] => 4 ) [4] => Array ( [start] => 32 [label] => 5 ) [5] => Array ( [start] => 40 [label] => 6 ) [6] => Array ( [start] => 48 [label] => 7 ) [7] => Array ( [start] => 56 [label] => 8 ) ) [estimatedResultCount] => 239000000 [currentPageIndex] => 0 [moreResultsUrl] => http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=Test [searchResultTime] => 0.19 ) ) [responseDetails] => [responseStatus] => 200) Edited February 12, 2015 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/294556-getting-more-than-4-results-google-search/#findComment-1505563 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.