### Google Trends API Request Example Source: https://serpapi.com/google-trends-api Example of a GET request to the Google Trends API endpoint to search for 'quantum computing'. This demonstrates the basic structure for querying the API. ```http GET https://serpapi.com/search?engine=google_trends&q=quantum+computing ``` -------------------------------- ### Google Trends API Request Example with tz Parameter Source: https://serpapi.com/google-trends-api This example demonstrates how to construct a URL for the Google Trends API, specifically including the 'tz' parameter to specify a time zone. The 'tz' parameter is crucial for ensuring time-sensitive data aligns correctly with the selected region's local time. ```url https://serpapi.com/search.json?engine=google_trends&q=sakura&date=now+7-d&tz=-540&data_type=TIMESERIES ``` -------------------------------- ### GET /websites/serpapi_google-trends-api Source: https://serpapi.com/google-trends-api Fetches Google Trends data for a specified query. The response includes a list of date ranges with corresponding search interest values. ```APIDOC ## GET /websites/serpapi_google-trends-api ### Description Retrieves Google Trends data for a given search query, showing search interest over time. ### Method GET ### Endpoint /websites/serpapi_google-trends-api ### Query Parameters - **q** (string) - Required - The search query for which to retrieve trends data. ### Response #### Success Response (200) - **date** (string) - The date range for the trend data (e.g., "Aug 10 – 16, 2025"). - **timestamp** (string) - The Unix timestamp for the start of the date range. - **values** (array) - An array of objects, where each object contains: - **query** (string) - The search query. - **value** (string) - The relative search interest score for the query during the date range. - **extracted_value** (integer) - The numerical representation of the search interest score. #### Response Example { "date": "Aug 10 – 16, 2025", "timestamp": "1754784000", "values": [ { "query": "quantum computing", "value": "14", "extracted_value": 14 } ] } ``` -------------------------------- ### GET /search.json (Google Trends Interest Over Time) Source: https://serpapi.com/google-trends-api Retrieves the interest over time for a list of search queries. The `q` parameter accepts a comma-separated list of search terms, and `data_type` should be set to `TIMESERIES`. ```APIDOC ## GET /search.json ### Description Retrieves the interest over time for a list of search queries. The `q` parameter accepts a comma-separated list of search terms, and `data_type` should be set to `TIMESERIES`. ### Method GET ### Endpoint https://serpapi.com/search.json ### Query Parameters - **engine** (string) - Required - The search engine to use, set to `google_trends`. - **q** (string) - Required - A comma-separated list of search terms (e.g., `coffee,milk,bread,pasta,steak`). - **data_type** (string) - Required - Set to `TIMESERIES` to get interest over time data. - **api_key** (string) - Required - Your SerpApi API key. ### Request Example ```json { "request": "GET https://serpapi.com/search.json?engine=google_trends&q=coffee,milk,bread,pasta,steak&data_type=TIMESERIES&api_key=YOUR_API_KEY" } ``` ### Response #### Success Response (200) - **search_metadata** (object) - Metadata about the search request. - **search_parameters** (object) - The parameters used for the search. - **interest_over_time** (object) - Contains the interest over time data, including `timeline_data` and `averages`. - **timeline_data** (array) - An array of objects, where each object represents a time period and contains `date`, `timestamp`, and `values` for each query. - **averages** (array) - An array of objects, where each object contains the average interest `value` for a given `query`. #### Response Example ```json { "search_metadata": { "id": "628e1083de983400a3b29c2e", "status": "Success", "json_endpoint": "https://serpapi.com/searches/c1bde9cbd0a44437/628e1083de983400a3b29c2e.json", "created_at": "2022-05-25 11:18:27 UTC", "processed_at": "2022-05-25 11:18:27 UTC", "google_trends_url": "https://trends.google.com/trends/api/explore?tz=420&req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22coffee%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%2C%7B%22keyword%22%3A%22milk%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%2C%7B%22keyword%22%3A%22bread%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%2C%7B%22keyword%22%3A%22pasta%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%2C%7B%22keyword%22%3A%22steak%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D", "raw_html_file": "https://serpapi.com/searches/c1bde9cbd0a44437/628e1083de983400a3b29c2e.html", "prettify_html_file": "https://serpapi.com/searches/c1bde9cbd0a44437/628e1083de983400a3b29c2e.prettify", "total_time_taken": 1.89 }, "search_parameters": { "engine": "google_trends", "q": "coffee,milk,bread,pasta,steak", "date": "today 12-m", "tz": "420", "data_type": "TIMESERIES" }, "interest_over_time": { "timeline_data": [ { "date": "May 30 – Jun 5, 2021", "timestamp": "1622304000", "values": [ { "query": "coffee", "value": "80", "extracted_value": 80 }, { "query": "milk", "value": "58", "extracted_value": 58 }, { "query": "bread", "value": "35", "extracted_value": 35 } ] } ], "averages": [ { "query": "coffee", "value": 84 }, { "query": "milk", "value": 55 }, { "query": "bread", "value": 39 } ] } } ``` ``` -------------------------------- ### Google Trends API JSON Response Structure Source: https://serpapi.com/google-trends-api Example JSON output from the Google Trends API. It includes search metadata, the parameters used for the search, and detailed 'interest_over_time' data for the queried term. ```json { "search_metadata": { "id": "695928708c24bd247f1be805", "status": "Success", "json_endpoint": "https://serpapi.com/searches/7e338dcb660fd739/695928708c24bd247f1be805.json", "created_at": "2026-01-03 14:32:16 UTC", "processed_at": "2026-01-03 14:32:16 UTC", "google_trends_url": "https://trends.google.com/trends/embed/explore/TIMESERIES?hl=en&tz=420&req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22quantum+computing%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D", "raw_html_file": "https://serpapi.com/searches/7e338dcb660fd739/695928708c24bd247f1be805.html", "prettify_html_file": "https://serpapi.com/searches/7e338dcb660fd739/695928708c24bd247f1be805.prettify", "total_time_taken": 0.94 }, "search_parameters": { "engine": "google_trends", "q": "quantum computing", "hl": "en", "date": "today 12-m", "tz": "420", "data_type": "TIMESERIES" }, "interest_over_time": { "timeline_data": [ { "date": "Dec 29, 2024 – Jan 4, 2025", "timestamp": "1735430400", "values": [ { "query": "quantum computing", "value": "8", "extracted_value": 8 } ] }, { "date": "Jan 5 – 11, 2025", "timestamp": "1736035200", "values": [ { "query": "quantum computing", "value": "11", "extracted_value": 11 } ] }, { "date": "Jan 12 – 18, 2025", "timestamp": "1736640000", "values": [ { "query": "quantum computing", "value": "10", "extracted_value": 10 } ] }, { "date": "Jan 19 – 25, 2025", "timestamp": "1737244800", "values": [ { "query": "quantum computing", "value": "7", "extracted_value": 7 } ] }, { "date": "Jan 26 – Feb 1, 2025", "timestamp": "1737849600", "values": [ { "query": "quantum computing", "value": "6", "extracted_value": 6 } ] }, { "date": "Feb 2 – 8, 2025", "timestamp": "1738454400", "values": [ { "query": "quantum computing", "value": "5", "extracted_value": 5 } ] }, { "date": "Feb 9 – 15, 2025", "timestamp": "1739059200", "values": [ { "query": "quantum computing", "value": "6", "extracted_value": 6 } ] }, { "date": "Feb 16 – 22, 2025", "timestamp": "1739664000", "values": [ { "query": "quantum computing", "value": "11", "extracted_value": 11 } ] }, { "date": "Feb 23 – Mar 1, 2025", "timestamp": "1740268800", "values": [ { "query": "quantum computing", "value": "8", "extracted_value": 8 } ] }, { "date": "Mar 2 – 8, 2025", "timestamp": "1740873600", "values": [ { "query": "quantum computing", "value": "5", "extracted_value": 5 } ] }, { "date": "Mar 9 – 15, 2025", "timestamp": "1741478400", "values": [ { "query": "quantum computing", "value": "5", "extracted_value": 5 } ] }, { "date": "Mar 16 – 22, 2025", "timestamp": "1742083200", "values": [ { "query": "quantum computing", "value": "6", "extracted_value": 6 } ] }, { "date": "Mar 23 – 29, 2025", "timestamp": "1742688000", "values": [ { "query": "quantum computing", "value": "5", "extracted_value": 5 } ] }, { "date": "Mar 30 – Apr 5, 2025", "timestamp": "1743292800", "values": [ { "query": "quantum computing", "value": "5", "extracted_value": 5 } ] } ] } } ``` -------------------------------- ### GET /search.json?engine=google_trends&q=coffee&data_type=RELATED_TOPICS Source: https://serpapi.com/google-trends-api Retrieves related topics for the search query 'coffee' using the Google Trends engine. ```APIDOC ## GET /search.json ### Description Retrieves related topics for a given search query from Google Trends. This endpoint is useful for understanding trending subjects associated with a specific keyword. ### Method GET ### Endpoint https://serpapi.com/search.json ### Parameters #### Query Parameters - **engine** (string) - Required - The search engine to use, in this case, `google_trends`. - **q** (string) - Required - The search query for which to find related topics (e.g., `coffee`). - **data_type** (string) - Required - Specifies the type of data to retrieve. Use `RELATED_TOPICS` for this endpoint. - **api_key** (string) - Required - Your SerpApi API key. ### Request Example ```json { "example": "https://serpapi.com/search.json?engine=google_trends&q=coffee&data_type=RELATED_TOPICS&api_key=YOUR_API_KEY" } ``` ### Response #### Success Response (200) - **search_metadata** (object) - Metadata about the search request. - **search_parameters** (object) - The parameters used for the search. - **related_topics** (object) - An object containing lists of 'rising' and 'top' related topics. - **rising** (array) - List of topics with a significant increase in search interest. - **top** (array) - List of the most popular related topics. #### Response Example ```json { "search_metadata": { "id": "628e148bde983400a3b29c2f", "status": "Success", "json_endpoint": "https://serpapi.com/searches/15f6e17aed843e35/628e148bde983400a3b29c2f.json", "created_at": "2022-05-25 11:35:39 UTC", "processed_at": "2022-05-25 11:35:39 UTC", "google_trends_url": "https://trends.google.com/trends/api/explore?tz=420&req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22coffee%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D", "raw_html_file": "https://serpapi.com/searches/15f6e17aed843e35/628e148bde983400a3b29c2f.html", "prettify_html_file": "https://serpapi.com/searches/15f6e17aed843e35/628e148bde983400a3b29c2f.prettify", "total_time_taken": 1.92 }, "search_parameters": { "engine": "google_trends", "q": "coffee", "date": "today 12-m", "tz": "420", "data_type": "RELATED_TOPICS" }, "related_topics": { "rising": [ { "topic": { "value": "/g/11qrhc4zy2", "title": "Coffee and lemon", "type": "Food" }, "value": "+2,300%", "extracted_value": 2300, "link": "https://trends.google.com/trends/explore?q=/g/11qrhc4zy2&date=today+12-m", "serpapi_link": "https://serpapi.com/search.json?data_type=RELATED_TOPICS&date=today+12-m&engine=google_trends&q=/g/11qrhc4zy2&tz=420" } ], "top": [ { "topic": { "value": "/m/02vqfm", "title": "Coffee", "type": "Drink" }, "value": "100", "extracted_value": 100, "link": "https://trends.google.com/trends/explore?q=/m/02vqfm&date=today+12-m", "serpapi_link": "https://serpapi.com/search.json?data_type=RELATED_TOPICS&date=today+12-m&engine=google_trends&q=/m/02vqfm&tz=420" } ] } } ``` ``` -------------------------------- ### GET /search.json - Compared breakdown by region chart Source: https://serpapi.com/google-trends-api Fetches a chart comparing the breakdown by region for a list of search queries using the Google Trends engine. ```APIDOC ## GET /search.json - Compared breakdown by region chart ### Description This endpoint retrieves a regional breakdown of Google Trends data for a specified set of search queries. It's useful for understanding how search interest for different terms varies across geographical locations. ### Method GET ### Endpoint https://serpapi.com/search.json ### Parameters #### Query Parameters - **engine** (string) - Required - The search engine to use, set to `google_trends`. - **q** (string) - Required - A comma-separated list of search queries to compare (e.g., `coffee,milk,bread,pasta,steak`). - **data_type** (string) - Required - Specifies the type of data to retrieve, set to `GEO_MAP` for regional breakdown. - **api_key** (string) - Required - Your SerpApi API key. ### Request Example ```json { "engine": "google_trends", "q": "coffee,milk,bread,pasta,steak", "data_type": "GEO_MAP", "api_key": "YOUR_SERPAPI_KEY" } ``` ### Response #### Success Response (200) - **search_metadata** (object) - Contains metadata about the search request. - **search_parameters** (object) - Details of the parameters used in the search. - **compared_breakdown_by_region** (array) - An array of objects, where each object represents a region and contains the search interest values for the queried terms within that region. - **geo** (string) - The geographical code for the region. - **location** (string) - The name of the region. - **max_value_index** (integer) - The index of the query with the highest search interest in this region. - **values** (array) - An array of objects, each detailing the search interest for a specific query. - **query** (string) - The search query. - **value** (string) - The relative search interest value (e.g., "43%"). - **extracted_value** (integer) - The numerical representation of the search interest. #### Response Example ```json { "search_metadata": { "id": "628e1291de983400a5961cdc", "status": "Success", "json_endpoint": "https://serpapi.com/searches/c1bde9cbd0a44437/628e1291de983400a5961cdc.json", "created_at": "2022-05-25 11:27:13 UTC", "processed_at": "2022-05-25 11:27:14 UTC", "google_trends_url": "https://trends.google.com/trends/api/explore?tz=420&req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22coffee%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%2C%7B%22keyword%22%3A%22milk%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%2C%7B%22keyword%22%3A%22bread%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%2C%7B%22keyword%22%3A%22pasta%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%2C%7B%22keyword%22%3A%22steak%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D", "raw_html_file": "https://serpapi.com/searches/c1bde9cbd0a44437/628e1291de983400a5961cdc.html", "prettify_html_file": "https://serpapi.com/searches/c1bde9cbd0a44437/628e1291de983400a5961cdc.prettify", "total_time_taken": 1.73 }, "search_parameters": { "engine": "google_trends", "q": "coffee,milk,bread,pasta,steak", "date": "today 12-m", "tz": "420", "data_type": "GEO_MAP" }, "compared_breakdown_by_region": [ { "geo": "SG", "location": "Singapore", "max_value_index": 0, "values": [ { "query": "coffee", "value": "43%", "extracted_value": 43 }, { "query": "milk", "value": "25%", "extracted_value": 25 }, { "query": "bread", "value": "16%", "extracted_value": 16 }, { "query": "pasta", "value": "10%", "extracted_value": 10 }, { "query": "steak", "value": "6%", "extracted_value": 6 } ] }, { "geo": "IT", "location": "Italy", "max_value_index": 3, "values": [ { "query": "coffee", "value": "5%", "extracted_value": 5 }, { "query": "milk", "value": "3%", "extracted_value": 3 }, { "query": "bread", "value": "2%", "extracted_value": 2 }, { "query": "pasta", "value": "1%", "extracted_value": 1 }, { "query": "steak", "value": "0%", "extracted_value": 0 } ] }, { "geo": "AU", "location": "Australia", "max_value_index": 0, "values": [ { "query": "coffee", "value": "38%", "extracted_value": 38 }, { "query": "milk", "value": "21%", "extracted_value": 21 }, { "query": "bread", "value": "17%", "extracted_value": 17 }, { "query": "pasta", "value": "12%", "extracted_value": 12 }, { "query": "steak", "value": "12%", "extracted_value": 12 } ] } ] } ``` ``` -------------------------------- ### Get Compared Breakdown by Region (Ruby) Source: https://serpapi.com/google-trends-api This code snippet demonstrates how to use the SerpApi Ruby client to retrieve a compared breakdown by region from Google Trends. It requires the 'serpapi' gem and an API key. The output is a hash containing the search results, including 'compared_breakdown_by_region'. ```Ruby require "serpapi" client = SerpApi::Client.new( engine: "google_trends", q: "coffee,milk,bread,pasta,steak", data_type: "GEO_MAP", api_key: "secret_api_key" ) results = client.search compared_breakdown_by_region = results[:compared_breakdown_by_region] ``` -------------------------------- ### Get Related Queries Chart with SerpApi Google Trends API (Ruby) Source: https://serpapi.com/google-trends-api This Ruby code snippet demonstrates how to use the SerpApi client to fetch related queries for 'coffee' from Google Trends. It requires the 'serpapi' gem and an API key. The output is a hash containing related queries, categorized into 'rising' and 'top'. ```Ruby require "serpapi" client = SerpApi::Client.new( engine: "google_trends", q: "coffee", data_type: "RELATED_QUERIES", api_key: "secret_api_key" ) results = client.search related_queries = results[:related_queries] ``` -------------------------------- ### Google Trends API: Search by Category (Ruby) Source: https://serpapi.com/google-trends-api Integrate Google Trends API into your Ruby application to search for trends within a specified category (ID 319). This example uses the SerpApi Ruby client, requiring an API key and setting the 'google_trends' engine and 'cat' parameter. ```ruby require "serpapi" client = SerpApi::Client.new( engine: "google_trends", cat: "319", api_key: "secret_api_key" ) results = client.search ``` -------------------------------- ### Get Interest Over Time Chart Data (Google Trends API) Source: https://serpapi.com/google-trends-api This snippet demonstrates how to retrieve 'Interest over time' data for a list of search queries using the SerpApi Google Trends API. It requires the 'q' parameter for search terms and 'data_type' set to 'TIMESERIES'. The output is a JSON object containing timeline data and averages for each query. ```cURL curl -X GET "https://serpapi.com/search.json?engine=google_trends&q=coffee,milk,bread,pasta,steak&data_type=TIMESERIES" ``` ```Ruby require "serpapi" client = SerpApi::Client.new( engine: "google_trends", q: "coffee,milk,bread,pasta,steak", data_type: "TIMESERIES", api_key: "secret_api_key" ) results = client.search interest_over_time = results[:interest_over_time] ``` ```Python import os from serpapi import GoogleTrends params = { "engine": "google_trends", "q": "coffee,milk,bread,pasta,steak", "data_type": "TIMESERIES", "api_key": os.getenv("SERPAPI_API_KEY") } client = GoogleTrends(params) results = client.get_dict() ``` ```JavaScript const { GoogleTrends } = require("serpapi"); new GoogleTrends({ engine: "google_trends", q: "coffee,milk,bread,pasta,steak", data_type: "TIMESERIES", api_key: "YOUR_API_KEY" }).json().then(result => { console.log(result["interest_over_time"]); }); ``` ```Go package main import ( "fmt" "os" "github.com/serpapi/serpapi-go" ) func main() { params := map[string]string{ "engine": "google_trends", "q": "coffee,milk,bread,pasta,steak", "data_type": "TIMESERIES", "api_key": os.Getenv("SERPAPI_API_KEY") } client := serpapi.NewClient(params) result, err := client.Get("google_trends") if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) return } interestOverTime := (*result)["interest_over_time"] fmt.Println(interestOverTime) } ``` ```PHP "google_trends", "q" => "coffee,milk,bread,pasta,steak", "data_type" => "TIMESERIES", "api_key" => "YOUR_API_KEY" ]); $json = $client->json(); print_r($json["interest_over_time"]); ?> ``` ```Java import com.google.gson.JsonObject; import com.serpapi.GoogleTrends; import java.util.HashMap; import java.util.Map; public class GoogleTrendsExample { public static void main(String[] args) { Map params = new HashMap<>(); params.put("engine", "google_trends"); params.put("q", "coffee,milk,bread,pasta,steak"); params.put("data_type", "TIMESERIES"); params.put("api_key", "YOUR_API_KEY"); GoogleTrends client = new GoogleTrends(params); JsonObject results = client.json(); System.out.println(results.getAsJsonObject("interest_over_time")); } } ``` ```Rust use std::collections::HashMap; use std::env; use serpapi::GoogleTrends; #[tokio::main] async fn main() { let mut params: HashMap = HashMap::new(); params.insert("engine".to_string(), "google_trends".to_string()); params.insert("q".to_string(), "coffee,milk,bread,pasta,steak".to_string()); params.insert("data_type".to_string(), "TIMESERIES".to_string()); params.insert("api_key".to_string(), env::var("SERPAPI_API_KEY").unwrap()); let client = GoogleTrends::new(params); let results = client.json().await; match results { Ok(json) => { println!("{}", json["interest_over_time"]); } Err(e) => { eprintln!("Error: {}", e); } } } ``` ```.NET using System; using System.Collections.Generic; using System.Threading.Tasks; using SerpApi; public class GoogleTrendsExample { public static async Task Main(string[] args) { var parameters = new Dictionary { { "engine", "google_trends" }, { "q", "coffee,milk,bread,pasta,steak" }, { "data_type", "TIMESERIES" }, { "api_key", Environment.GetEnvironmentVariable("SERPAPI_API_KEY") } }; var client = new GoogleTrends(parameters); var results = await client.JsonAsync(); Console.WriteLine(results["interest_over_time"]); } } ``` -------------------------------- ### Fetch Google Trends Time Series Data (Ruby) Source: https://serpapi.com/google-trends-api This Ruby code snippet shows how to use the SerpApi client to retrieve time series data for 'quantum computing'. It requires the 'serpapi' gem and an API key, and extracts the 'interest_over_time' from the results. ```ruby require "serpapi" client = SerpApi::Client.new( engine: "google_trends", q: "quantum computing", date: "today 12-m", tz: "420", data_type: "TIMESERIES", api_key: "secret_api_key" ) results = client.search interest_over_time = results[:interest_over_time] ``` -------------------------------- ### Fetch Google Trends Compared Breakdown by Region (Go) Source: https://serpapi.com/google-trends-api This Go code snippet shows how to use the SerpApi Go client to retrieve geographical search interest data. It sets up the API request with specific parameters for multiple search queries and includes low search volume regions. ```go package main import ( "fmt" "log" "os" "github.com/serpapi/serpapi-go" ) func main() { params := map[string]string{ "engine": "google_trends", "q": "Football, Basketball, Golf", "data_type": "GEO_MAP", "include_low_search_volume": "true", "api_key": os.Getenv("SERPAPI_API_KEY"), } client := serpapi.NewClient(params) result, err := client.Get("google_trends") if err != nil { log.Fatal(err) } fmt.Println(result) } ``` -------------------------------- ### Fetch Google Trends Compared Breakdown by Region (.NET) Source: https://serpapi.com/google-trends-api This .NET code snippet shows how to use the SerpApi .NET client to retrieve geographical search interest data. It sets up the API request with specific parameters for multiple search queries and includes low search volume regions. ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using SerpApi; public class GoogleTrendsExample { public static async Task Main(string[] args) { var parameters = new Dictionary { { "engine", "google_trends" }, { "q", "Football, Basketball, Golf" }, { "data_type", "GEO_MAP" }, { "include_low_search_volume", "true" }, { "api_key", Environment.GetEnvironmentVariable("SERPAPI_API_KEY") } }; using (var client = new GoogleTrends(parameters)) { var results = await client.GetJsonAsync(); Console.WriteLine(results); } } } ``` -------------------------------- ### Integrate Google Trends API with Ruby using tz Parameter Source: https://serpapi.com/google-trends-api This Ruby code snippet shows how to use the SerpApi client to fetch Google Trends data. It includes the 'tz' parameter to specify the time zone, ensuring accurate time-series data for queries like 'sakura'. The 'api_key' should be replaced with your actual SerpApi key. ```ruby require "serpapi" client = SerpApi::Client.new( engine: "google_trends", q: "sakura", date: "now 7-d", tz: "-540", data_type: "TIMESERIES", api_key: "secret_api_key" ) results = client.search interest_over_time = results[:interest_over_time] ``` -------------------------------- ### GET /search.json - Interest by Region Source: https://serpapi.com/google-trends-api Retrieves interest by region data for a specified search query using the Google Trends engine. This endpoint is useful for understanding geographical trends of a topic. ```APIDOC ## GET /search.json - Interest by Region ### Description Retrieves interest by region data for a specified search query using the Google Trends engine. This endpoint is useful for understanding geographical trends of a topic. ### Method GET ### Endpoint https://serpapi.com/search.json ### Query Parameters - **engine** (string) - Required - The search engine to use, set to `google_trends`. - **q** (string) - Required - The search query (e.g., `coffee`). - **data_type** (string) - Required - The type of data to retrieve, set to `GEO_MAP_0` for interest by region. - **api_key** (string) - Required - Your SerpApi license key. ### Request Example ```json { "q": "coffee", "data_type": "GEO_MAP_0", "engine": "google_trends", "api_key": "YOUR_SERPAPI_KEY" } ``` ### Response #### Success Response (200) - **search_metadata** (object) - Metadata about the search request. - **search_parameters** (object) - Parameters used for the search. - **interest_by_region** (array) - An array of objects, where each object contains geographical data (geo, location, value) indicating the interest level for the query in that region. #### Response Example ```json { "search_metadata": { "id": "628e13d2de983400a5961cdf", "status": "Success", "json_endpoint": "https://serpapi.com/searches/15f6e17aed843e35/628e13d2de983400a5961cdf.json", "created_at": "2022-05-25 11:32:34 UTC", "processed_at": "2022-05-25 11:32:34 UTC", "google_trends_url": "https://trends.google.com/trends/api/explore?tz=420&req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22coffee%22%2C%22geo%22%3A%22%22%2C%22time%22%3A%22today+12-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D", "raw_html_file": "https://serpapi.com/searches/15f6e17aed843e35/628e13d2de983400a5961cdf.html", "prettify_html_file": "https://serpapi.com/searches/15f6e17aed843e35/628e13d2de983400a5961cdf.prettify", "total_time_taken": 1.85 }, "search_parameters": { "engine": "google_trends", "q": "coffee", "date": "today 12-m", "tz": "420", "data_type": "GEO_MAP_0" }, "interest_by_region": [ { "geo": "SG", "location": "Singapore", "max_value_index": 0, "value": "100", "extracted_value": 100 }, { "geo": "AU", "location": "Australia", "max_value_index": 0, "value": "87", "extracted_value": 87 }, { "geo": "NZ", "location": "New Zealand", "max_value_index": 0, "value": "77", "extracted_value": 77 } ] } ``` ``` -------------------------------- ### GET /search.json (Google Trends - Category Search) Source: https://serpapi.com/google-trends-api Retrieves Google Trends data filtered by a specified category without a query. This is useful for exploring general trends within a category. ```APIDOC ## GET /search.json (Google Trends - Category Search) ### Description Retrieves Google Trends data filtered by a specified category without a query. This is useful for exploring general trends within a category. ### Method GET ### Endpoint https://serpapi.com/search.json ### Parameters #### Query Parameters - **engine** (string) - Required - The search engine to use, must be `google_trends`. - **cat** (integer) - Required - The category ID to filter trends by. For example, `319` for Cartoons. - **api_key** (string) - Required - Your SerpApi key. ### Request Example ```json { "engine": "google_trends", "cat": "319", "api_key": "YOUR_SERPAPI_KEY" } ``` ### Response #### Success Response (200) - **search_parameters** (object) - The parameters used for the search. - **interest_over_time** (object) - Contains the timeline data for the trends. - **timeline_data** (array) - An array of objects, each representing a time period with its trend value. - **date** (string) - The date range for the data point. - **timestamp** (string) - The Unix timestamp for the data point. - **values** (array) - An array of objects containing the trend value. - **value** (string) - The trend value for the period. - **extracted_value** (integer) - The extracted numerical trend value. #### Response Example ```json { "search_parameters": { "engine": "google_trends", "cat": "319", "date": "today 12-m", "tz": "420", "data_type": "TIMESERIES" }, "interest_over_time": { "timeline_data": [ { "date": "Apr 30–May 6, 2023", "timestamp": "1682812800", "values": [ { "value": "81", "extracted_value": 81 } ] }, { "date": "May 7–13, 2023", "timestamp": "1683417600", "values": [ { "value": "77", "extracted_value": 77 } ] }, { "date": "May 14–20, 2023", "timestamp": "1684022400", "values": [ { "value": "84", "extracted_value": 84 } ] } ] } } ``` ``` -------------------------------- ### Fetch Interest by Region Chart Data (Ruby) Source: https://serpapi.com/google-trends-api This Ruby code snippet uses the SerpApi client to fetch 'Interest by region' data for the query 'coffee'. It requires the 'serpapi' gem and an API key. The output is the 'interest_by_region' array from the JSON response. ```Ruby require "serpapi" client = SerpApi::Client.new( engine: "google_trends", q: "coffee", data_type: "GEO_MAP_0", api_key: "secret_api_key" ) results = client.search interest_by_region = results[:interest_by_region] ``` -------------------------------- ### Fetch Google Trends Compared Breakdown by Region (Rust) Source: https://serpapi.com/google-trends-api This Rust code snippet demonstrates how to use the SerpApi Rust client to fetch geographical search interest data. It configures the API request with parameters for multiple search queries and includes an option for low search volume regions. ```rust use std::collections::HashMap; use std::env; use serpapi::GoogleTrends; #[tokio::main] async fn main() -> Result<(), Box> { let mut params = HashMap::new(); params.insert("engine".to_string(), "google_trends".to_string()); params.insert("q".to_string(), "Football, Basketball, Golf".to_string()); params.insert("data_type".to_string(), "GEO_MAP".to_string()); params.insert("include_low_search_volume".to_string(), "true".to_string()); params.insert("api_key".to_string(), env::var("SERPAPI_API_KEY")?); let client = GoogleTrends::new(params); let result = client.get_json().await?; println!("{}", result); Ok(()) } ```