Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com
This is where your description should go.
You can install the package via composer:
composer require zanysoft/laravel-serpapi
You can publish the config file with:
php artisan vendor:publish --provider="ZanySoft\LaravelSerpApi\SerpApiServiceProvider" --tag="serpapi-config"
This is the contents of the published config file:
return [
'api_key' => env('SERPAPI_API_KEY'),
'search_engine' => env('SERPAPI_ENGINE', 'google')
];
Get “your api key” from https://serpapi.com/dashboard
Then you can start coding something like:
use ZanySoft\LaravelSerpApi\Facades\SerpApi;
$client = SerpApi::GoogleSearch();
$query = ["q" => "coffee","location"=>"Austin,Texas"];
$response = $client->get_json($query);
print_r($response)
Alternatively, you can search:
SerpApi::BingSearch()
SerpApi::BaiduSearch()
SerpApi::EbaySearch()
SerpApi::YahooSearch()
SerpApi::YandexSearch()
SerpApi::WalmartSearch()
SerpApi::YoutubeSearch()
SerpApi::Search($engine)
SerpApi::Search($engine)
SerpApi::NaverSearch()
See the playground to generate your code. https://serpapi.com/playground
use ZanySoft\LaravelSerpApi\Facades\SerpApi;
$client = SerpApi::GoogleSearch();
$query = [
"q" => "query",
"google_domain" => "Google Domain",
"location" => "Location Requested",
"device" => "device",
"hl" => "Google UI Language",
"gl" => "Google Country",
"safe" => "Safe Search Flag",
"num" => "Number of Results",
"start" => "Pagination Offset",
"serp_api_key" => "Your SERP API Key",
"tbm" => "nws|isch|shop"
"tbs" => "custom to be search criteria"
"async" => true|false # allow async
];
$html_results = $client->get_html($query);
$json_results = $client->get_json($query);
use ZanySoft\LaravelSerpApi\Facades\SerpApi;
$client = SerpApi::GoogleSearch();
$location_list = $client->get_location('Austin', 3);
print_r($location_list);
it prints the first 3 location matching Austin (Texas, Texas, Rochester)
[{:id=>"585069bdee19ad271e9bc072",
:google_id=>200635,
:google_parent_id=>21176,
:name=>"Austin, TX",
:canonical_name=>"Austin,TX,Texas,United States",
:country_code=>"US",
:target_type=>"DMA Region",
:reach=>5560000,
:gps=>[-97.7430608, 30.267153],
:keys=>["austin", "tx", "texas", "united", "states"]},
...]
use ZanySoft\LaravelSerpApi\Facades\SerpApi;
$client = SerpApi::GoogleSearch();
$info = $client->get_account();
print_r($info);
it prints your account information.
use ZanySoft\LaravelSerpApi\Facades\SerpApi;
$client = SerpApi::GoogleSearch();
$data = $client->get_json([
'q' => "Coffee",
'tbm' => 'isch'
]);
foreach($data->images_results as $image_result) {
print_r($image_result->original);
}
this code prints all the images links
SerpApi supports all the major search engines. Google has the more advance support with all the major services available: Images, News, Shopping and more.. To enable a type of search, the field tbm (to be matched) must be set to:
The full documentation is available here.
The MIT License (MIT). Please see License File for more information.