### Ruby Integration Example Source: https://serpapi.com/playground?gl=us&google_domain=google.com&hl=en&location=Austin%2C+Texas%2C+United+States&newPara=stick+highlight+lr+as_qdr+safe+google_domain+si+form+filter+chips+as_epq+client+votes+site+ie+oe+pws+ibp+source+as_sitesearch+ijn+rlz+interval+size+color+maxPrice+as_dt+direct_link&q=successful+quotes Demonstrates how to initialize the SerpApi client and perform a search using Ruby. Ensure you have the 'serpapi' gem installed. ```ruby require "serpapi" client = SerpApi::Client.new( documentation_path: "/search-api", engine: "google", google_domain: "google.com", q: "successful quotes", gl: "us", hl: "en", location: "Austin, Texas, United States", api_key: "secret_api_key" ) results = client.search ``` -------------------------------- ### Example GET Request with Pagination Source: https://serpapi.com/pagination Demonstrates a GET request to the SerpApi endpoint including the 'start' parameter for pagination. ```HTTP https://serpapi.com/search.json?q=coffee&start=50 ``` -------------------------------- ### Get Google Search Results with Episode Guide Source: https://serpapi.com/episode-guide This example shows how to make a direct GET request to the SerpApi Google search endpoint to retrieve results, including episode guide information. ```cURL https://serpapi.com/search.json?engine=google&q=Midnight+Mass ``` -------------------------------- ### Ruby Integration Example Source: https://serpapi.com/google-maps-directions-api This Ruby code snippet demonstrates how to initialize the SerpApi client with your API key and search parameters, then retrieve directions. ```Ruby require "serpapi" client = SerpApi::Client.new( engine: "google_maps_directions", start_addr: "Austin-Bergstrom International Airport", end_addr: "5540 N Lamar Blvd, Austin, TX 78756, USA", api_key: "secret_api_key" ) results = client.search directions = results[:directions] ``` -------------------------------- ### Initialize SerpApi Client and Search in Ruby Source: https://serpapi.com/playground?gl=us&hl=en&q=boots.com Demonstrates how to initialize the SerpApi client with API key and search parameters, then execute a search in Ruby. ```ruby require "serpapi" client = SerpApi::Client.new( documentation_path: "/search-api", engine: "google", q: "boots.com", google_domain: "google.com", gl: "us", hl: "en", api_key: "secret_api_key" ) results = client.search ``` -------------------------------- ### Google Maps Pagination GET Request Source: https://serpapi.com/maps-local-results This is a GET request example for retrieving the second page of Google Maps results for 'coffee'. The 'start' parameter defines the offset for pagination, and 'll' is required for GPS coordinates. ```HTTP https://serpapi.com/search.json?engine=google_maps&q=coffee&ll=@40.7455096,-74.0083012,14z&start=20&type=search ``` -------------------------------- ### Ruby Integration Example Source: https://serpapi.com/?FORM=Z9FD1 Example of how to integrate with SerpApi using the Ruby client library. This demonstrates initializing the client with search parameters and executing a search. ```APIDOC ## Ruby Client Integration ### Description This code snippet shows how to use the SerpApi Ruby client to perform a search. It includes setting up the client with API key and search parameters. ### Method Client Initialization and Search Execution ### Endpoint N/A (Client Library) ### Parameters - **q** (string) - Required - The search query. - **location** (string) - Required - The location for the search. - **hl** (string) - Optional - The language for the search. - **gl** (string) - Optional - The Google domain to use. - **google_domain** (string) - Optional - The Google domain to use. - **api_key** (string) - Required - Your SerpApi secret API key. ### Request Example ```ruby require "serpapi" client = SerpApi::Client.new( q: "Coffee", location: "Austin, Texas, United States", hl: "en", gl: "us", google_domain: "google.com", api_key: "secret_api_key" ) results = client.search ``` ### Response #### Success Response The `results` variable will contain the structured JSON response from the SerpApi search. #### Response Example ```json { "example": "(JSON response object similar to the GET /search.json endpoint)" } ``` ``` -------------------------------- ### Brave AI Mode Search (cURL) Source: https://serpapi.com/brave-ai-mode-api Perform a search using the Brave AI Mode API via cURL. This is a basic example to get started. ```bash https://serpapi.com/search.json?engine=brave_ai_mode&q=Coffee ``` -------------------------------- ### Ruby Integration Example Source: https://serpapi.com/playground?highlight=immersive_products&q=laptops This snippet shows how to initialize the SerpApi client in Ruby and perform a search for 'laptops'. Ensure you have the 'serpapi' gem installed and replace 'secret_api_key' with your actual API key. ```Ruby require "serpapi" client = SerpApi::Client.new( documentation_path: "/search-api", engine: "google", q: "laptops", google_domain: "google.com", api_key: "secret_api_key" ) results = client.search ``` -------------------------------- ### Paginate Google Search Results Source: https://serpapi.com/blog/how-to-scrape-google-search-results-with-python Retrieve subsequent pages of Google search results by specifying the 'start' parameter. This example shows how to get the third page of results. ```python result = client.search( ... start=20 ) print(result) ``` -------------------------------- ### Get Mobile Shopping Results for Xiaomi Source: https://serpapi.com/baidu-shopping-results This example demonstrates how to retrieve mobile shopping results for a specific query using the Baidu engine. Ensure you have the SerpApi client library installed. ```cURL https://serpapi.com/search.json?engine=baidu&q=xiaomi&device=mobile ``` ```Ruby require "serpapi" client = SerpApi::Client.new( engine: "baidu", q: "xiaomi", device: "mobile", api_key: "secret_api_key" ) results = client.search shopping_results = results[:shopping_results] ``` ```Python import os from serpapi import GoogleSearch params = { "engine": "baidu", "q": "xiaomi", "device": "mobile", "api_key": os.getenv("SERPAPI_API_KEY") } search = GoogleSearch(params) results = search.get_dict() ``` ```JavaScript const serpApi = require('serpapi') serpApi.search({ engine: "baidu", q: "xiaomi", device: "mobile", api_key: "secret_api_key" }).then(results => { console.log(JSON.stringify(results, null, 2)) }) ``` ```Go package main import ( "fmt" "os" "github.com/serpapi/serpapi-go" ) func main() { client := serpapi.NewClient(os.Getenv("SERPAPI_API_KEY")) result, err := client.Search(map[string]string{ "engine": "baidu", "q": "xiaomi", "device": "mobile", }) if err != nil { fmt.Println("Error:", err) return } fmt.Println(result["shopping_results"]) } ``` ```PHP "baidu", "q" => "xiaomi", "device" => "mobile", "api_key" => "secret_api_key" ]); $result = $client->get_json(); print_r($result['shopping_results']); ?> ``` ```Java import com.google.gson.JsonObject; import com.google.gson.JsonParser; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import java.io.IOException; public class BaiduShopping { public static void main(String[] args) throws IOException { String apiKey = System.getenv("SERPAPI_API_KEY"); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://serpapi.com/search.json?engine=baidu&q=xiaomi&device=mobile&api_key="+apiKey) .build(); try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); JsonObject results = JsonParser.parseString(response.body().string()).getAsJsonObject(); System.out.println(results.getAsJsonArray("shopping_results")); } } } ``` ```Rust use reqwest::Error; #[tokio::main] async fn main() -> Result<(), Error> { let api_key = std::env::var("SERPAPI_API_KEY").expect("SERPAPI_API_KEY must be set"); let client = reqwest::Client::new(); let res = client.get(&format!("https://serpapi.com/search.json?engine=baidu&q=xiaomi&device=mobile&api_key={}", api_key)) .send() .await?; let json: serde_json::Value = res.json().await?; println!("{}", json["shopping_results"]); Ok(()) } ``` ```.NET using System; using System.Net.Http; using System.Threading.Tasks; public class BaiduShopping { public static async Task Main(string[] args) { var apiKey = Environment.GetEnvironmentVariable("SERPAPI_API_KEY"); using (var client = new HttpClient()) { var requestUrl = $"https://serpapi.com/search.json?engine=baidu&q=xiaomi&device=mobile&api_key={apiKey}"; var response = await client.GetAsync(requestUrl); response.EnsureSuccessStatusCode(); var json = await response.Content.ReadAsStringAsync(); Console.WriteLine(json); } } } ``` ```Google Sheets =IMPORTDATA("https://serpapi.com/search.json?engine=baidu&q=xiaomi&device=mobile&api_key=YOUR_API_KEY") ``` -------------------------------- ### Ruby Integration Example Source: https://serpapi.com/?kl=us-en&q=Apple+site%3Awww.washingtonpost.com Example of how to integrate with the SerpApi using the Ruby client library. This demonstrates initializing the client and performing a search. ```APIDOC ## Ruby Client Library ### Description Integrate with SerpApi using the official Ruby client. This example shows how to set up the client with your API key and search parameters, then execute a search. ### Language Ruby ### Code ```ruby require "serpapi" client = SerpApi::Client.new( q: "Coffee", location: "Austin, Texas, United States", hl: "en", gl: "us", google_domain: "google.com", api_key: "secret_api_key" ) results = client.search puts results ``` ``` -------------------------------- ### Ruby Integration Example Source: https://serpapi.com/?sa=X&ved=0ahUKEwiPqZadq9CUAxXUI0QIHaT6Je0QOwgC Example of how to integrate with SerpApi using the Ruby client library. This demonstrates initializing the client and performing a search. ```APIDOC ## Ruby Client Library ### Description Integrates with SerpApi using the provided Ruby client library to perform searches. ### Usage ```ruby require "serpapi" client = SerpApi::Client.new( q: "Coffee", location: "Austin, Texas, United States", hl: "en", gl: "us", google_domain: "google.com", api_key: "secret_api_key" ) results = client.search ``` ### Parameters - **q**: Search query. - **location**: Search location. - **hl**: Host language. - **gl**: Google domain. - **google_domain**: Google domain. - **api_key**: Your SerpApi secret key. ``` -------------------------------- ### Direct GET Request Example Source: https://serpapi.com/?kl=us-en&q=Apple+site%3Abusinessnc.com Example of a direct GET request to the SerpApi search endpoint. ```APIDOC ## GET /search.json ### Description This endpoint allows you to perform a search query and retrieve results directly via a GET request. ### Method GET ### Endpoint https://serpapi.com/search.json ### Query Parameters - **q** (string) - Required - The search query. - **location** (string) - Optional - The location for the search (e.g., "Austin, Texas, United States"). - **hl** (string) - Optional - The host language (e.g., "en"). - **gl** (string) - Optional - The host globalization (e.g., "us"). - **google_domain** (string) - Optional - The Google domain to use (e.g., "google.com"). ### Request Example ``` https://serpapi.com/search.json?q=Coffee&location=Austin,+Texas,+United+States&hl=en&gl=us&google_domain=google.com ``` ``` -------------------------------- ### Ruby SerpApi Client Initialization and Search Source: https://serpapi.com/playground?highlight=flight_result&q=Flight+IB5634 Demonstrates how to initialize the SerpApi client in Ruby with specific parameters like documentation path, engine, query, Google domain, and API key, then perform a search. ```ruby require "serpapi" client = SerpApi::Client.new( documentation_path: "/search-api", engine: "google", q: "Flight IB5634", google_domain: "google.com", api_key: "secret_api_key" ) results = client.search ``` -------------------------------- ### Get Baidu Mobile News Results for '小米' Source: https://serpapi.com/baidu-news-results This example demonstrates how to fetch mobile news results for the query '小米' using the Baidu engine. Ensure you have the SerpApi client library installed and your API key configured. ```ruby require "serpapi" client = SerpApi::Client.new( engine: "baidu", q: "小米", device: "mobile", api_key: "secret_api_key" ) results = client.search news_results = results[:news_results] ``` -------------------------------- ### Baidu Related Searches GET Request Example Source: https://serpapi.com/baidu-related-searches Example of a GET request to the Baidu Related Searches API for the query 'Coffee'. ```http https://serpapi.com/search.json?engine=baidu&q=Coffee ``` -------------------------------- ### Initialize SerpApi Client and Search for Videos (Ruby) Source: https://serpapi.com/playground?engine=google_videos&q=Coffee This snippet shows how to initialize the SerpApi client with specific parameters like engine, query, and API key, and then perform a video search. ```ruby require "serpapi" client = SerpApi::Client.new( documentation_path: "/google-videos-api", engine: "google_videos", q: "Coffee", google_domain: "google.com", api_key: "secret_api_key" ) results = client.search ``` -------------------------------- ### Example guide results with q: Coffee, and Austin, TX, US as a location Source: https://serpapi.com/apple-maps-guide-results This example demonstrates how to retrieve guide results for 'Coffee' in Austin, TX, US using the Apple Maps Guide Results API. ```APIDOC ## GET /search?engine=apple_maps ### Description Retrieves guide results from Apple Maps for a given query and location. ### Method GET ### Endpoint https://serpapi.com/search.json ### Parameters #### Query Parameters - **engine** (string) - Required - Specifies the search engine to use, in this case, `apple_maps`. - **query** (string) - Required - The search term (e.g., `Coffee`). - **center** (string) - Required - The latitude and longitude for the center of the search area (e.g., `30.324639,-97.7304611`). - **span** (string) - Required - The span of the search area in latitude and longitude (e.g., `0.05,0.05`). ### Request Example ``` https://serpapi.com/search.json?engine=apple_maps&query=Coffee¢er=30.324639,-97.7304611&span=0.05,0.05 ``` ### Response #### Success Response (200) - **guide_results** (array) - Contains a list of guide results. Each item may include: - **position** (integer) - The position of the guide result on the page. - **title** (string) - The title of the guide. - **description** (string) - A brief description of the guide. - **link** (string) - A link to the guide. - **apple_maps_link** (string) - A direct link to the guide in Apple Maps. - **item_count** (integer) - The number of items within the guide. - **publisher** (object) - Information about the publisher of the guide. - **photos** (array) - An array of photo objects associated with the guide. - **items** (array) - An array of items included in the guide. #### Response Example ```json { "guide_results": [ { "position": 1, "position_in_page": 6, "muid": "16505394090301289830", "provider_id": 9902, "title": "The Best Coffee Shops In Austin", "long_title": "The Best Coffee Shops In Austin", "description": "It's not hard to find a cup of coffee in Austin, but these are the best in the city.", "link": "https://www.theinfatuation.com/austin/guides/best-coffee-shops-austin?utm_campaign=applemaps&utm_medium=affiliate&utm_source=applemaps&utm_audience=austin&utm_campaigntype=organic", "apple_maps_link": "https://maps.apple.com/guides?curated=16505394090301289830&_provider=9902", "item_count": 15, "publisher": { "id": "3291963553709838958", "provider_id": "9902", "source_id": "com.infatuation", "name": "The Infatuation", "subtitle": "Your restaurant decider.", "link": "https://www.theinfatuation.com/?utm_campaign=applemaps&utm_medium=affiliate&utm_source=applemaps&utm_audience=all&utm_campaigntype=organic" }, "photos": [ { "link": "https://is1-ssl.mzstatic.com/image/thumb/_ZcsAHwIG7_W-SHgT0qQVA/1200x800.jpg", "width": 1200, "height": 800 } ], "items": [ { "muid": "994057644462772470", "provider_id": 9902, "link": "https://maps.apple.com/place?auid=994057644462772470&_provider=9902" } ] } ] } ``` -------------------------------- ### Ruby Search Example Source: https://serpapi.com/playground?q=how+to+brew+good+coffee This snippet shows how to initialize the SerpApi client in Ruby and perform a search for 'how to brew good coffee'. Ensure you have the 'serpapi' gem installed and your API key is set. ```ruby require "serpapi" client = SerpApi::Client.new( documentation_path: "/search-api", engine: "google", q: "how to brew good coffee", google_domain: "google.com", api_key: "secret_api_key" ) results = client.search ``` -------------------------------- ### Initialize and Search with Baidu API (Ruby) Source: https://serpapi.com/playground?engine=baidu&highlight=related_news&q=%E4%B8%AD%E5%9B%BD%E6%96%B0%E9%97%BB Demonstrates how to initialize the SerpApi client for Baidu searches and execute a search query. Ensure you have the SerpApi client library installed. ```ruby require "serpapi" client = SerpApi::Client.new( documentation_path: "/baidu-search-api", engine: "baidu", q: "中国新闻", api_key: "secret_api_key" ) results = client.search ``` -------------------------------- ### Google Related Questions API GET Request Example Source: https://serpapi.com/google-related-questions-api This is an example of a GET request to the Google Related Questions API. It includes the `engine` parameter and a `next_page_token` for pagination. ```HTTP https://serpapi.com/search.json?engine=google_related_questions&next_page_token=eyJvbnMiOiIxMDA0MSIsImZjIjoiRXFFQkNtSkJUR3QwWDNaSGVYaEhVbVpoYVdKb2JuUjZaVVY1TlZSWFpUWXlOVnBNTW14WU1YRjVPSEE1WkRKdWJGb3lOVTFUWlY4MFRHWk1lbXBsWkY5ZlZ6RmZkM0ZFVUhWS2NrUjVaMUpNYUZJdGVYaHVVRUUwYVdaNVQxSnBMVTVvTWxobFFSSVhkWGh3VVdGTmJuQkNkRU5uYTFCSlVHOXlRMkV3UVRRYUlrRkdUVUZIUjNKUldXcEdjM016TURWVVMxTnZSRFp0Tkc1R2FUSjVSRXRqY21jIiwiZmN2IjoiMyIsImVpIjoidXhwUWFNbnBCdENna1BJUG9yQ2EwQTQiLCJxYyI6IkNnVmphR2x1WVJBQWZZSm1MVDgiLCJxdWVzdGlvbiI6IkNhbiBhbiBBbWVyaWNhbiBnbyB0byBDaGluYT8iLCJsayI6ImM1T1NUazdNVXdDaDNOU2lUQkE3UFYtaEpGOGhPU016THhFQSIsImJzIjoiYy1PeTQ1TDFMRlp3enNqTVMxUW95a3pPU0MxU0tNbEl6QU1TcVFxaHdZNzJFdV9yaktTa0pES0xGWkl4MUpRV0ozSTVjTWs0QTVsQTVKaWJDcFFFTXRMekZVcnlJVWJhU19UbEc4bEtTU2REbENTaUtnR2J5R1hGSlJtZWtWaWlrQWwxaG5xeFFuNU9pa0llVUxHOXhHeDNrTzNsVVBsa05Ia3VKeTdaOEl4S3VGYUY1SnpFek56TXZIU0ZrTVRNOHNROGU0bXJva1p5VWpMbEVEWEpxR3BLd0dvRUdBRSIsImlkIjoiZmNfdXhwUWFNbnBCdENna1BJUG9yQ2EwQTRfMiJ9 ``` -------------------------------- ### Account API GET Request Example Source: https://serpapi.com/account-api This example shows how to make a GET request to the Account API endpoint to retrieve your account information. Replace 'SECRET_API_KEY' with your actual API key. ```bash https://serpapi.com/account?api_key=SECRET_API_KEY ``` -------------------------------- ### Ruby Integration Example Source: https://serpapi.com/google-light-api Example of how to integrate with the Google Light Search API using the SerpApi Ruby client. ```APIDOC ## Ruby Client Integration ### Description This code snippet demonstrates how to use the SerpApi Ruby client to perform a search with the Google Light engine and access the organic results. ### Language Ruby ### Code ```ruby require "serpapi" client = SerpApi::Client.new( engine: "google_light", q: "Coffee", location: "Austin, Texas, United States", google_domain: "google.com", hl: "en", gl: "us", api_key: "secret_api_key" ) results = client.search organic_results = results[:organic_results] ``` ```