### Install gogtrends Go Package Source: https://context7.com/groovili/gogtrends/llms.txt Use 'go get' to install the latest version of the gogtrends package. ```go go get -u github.com/groovili/gogtrends ``` -------------------------------- ### Explore Keywords and Get Related Data Source: https://github.com/groovili/gogtrends/blob/master/README.md Explores widgets for keywords, retrieves interest over time, interest by location, and related topics/queries. Requires a context and a configured ExploreRequest. ```go // Explore available widgets for keywords and get all available stats for it explore, err := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ { Keyword: "Go", Geo: "US", Time: "today 12-m", }, }, Category: 31, // Programming category Property: "", }, "EN") ``` ```go // Interest over time overTime, err := gogtrends.InterestOverTime(ctx, explore[0], "EN") ``` ```go // Interest by location byLoc, err := gogtrends.InterestByLocation(ctx, explore[1], "EN") ``` ```go // Related topics for keyword relT, err := gogtrends.Related(ctx, explore[2], "EN") ``` ```go // Related queries for keyword relQ, err := gogtrends.Related(ctx, explore[3], "EN") ``` -------------------------------- ### Get Available Realtime Trend Categories Source: https://github.com/groovili/gogtrends/blob/master/README.md Returns a map of available categories for realtime trends. No context or parameters are needed. ```go categories := gogtrends.TrendsCategories() ``` -------------------------------- ### Get Category Tree for Explore Source: https://github.com/groovili/gogtrends/blob/master/README.md Fetches a tree structure of categories for use with the Explore method. This data is cached after the first call. ```go categoryTree, err := gogtrends.ExploreCategories(ctx) ``` -------------------------------- ### Get Trends Categories and Realtime Trends Source: https://github.com/groovili/gogtrends/blob/master/README.md Fetches available trends categories and real-time trending searches for a given language and country. Supports filtering by category. ```go // Get available trends categories and realtime trends cats := gogtrends.TrendsCategories() realtime, err := gogtrends.Realtime(ctx, "EN", "US", "all") ``` -------------------------------- ### Get Location Tree for Explore Source: https://github.com/groovili/gogtrends/blob/master/README.md Fetches a tree structure of locations for use with the Explore method. This data is cached after the first call. ```go locationTree, err := gogtrends.ExploreLocations(ctx) ``` -------------------------------- ### Explore Widgets for Keywords Source: https://context7.com/groovili/gogtrends/llms.txt Use this to explore available widgets for keywords, which return tokens required for InterestOverTime, InterestByLocation, and Related methods. Supports single keyword analysis and multi-keyword comparison. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Single keyword explore explore, err := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ { Keyword: "Kubernetes", Geo: "US", Time: "today 12-m", // Last 12 months }, }, Category: 31, // Programming category Property: "", }, "EN") if err != nil { log.Fatal(err) } // Widgets returned (typically 4 for single keyword): // explore[0] - Interest over time widget (TIMESERIES) // explore[1] - Interest by location widget (GEO_MAP) // explore[2] - Related topics widget (RELATED_TOPICS) // explore[3] - Related queries widget (RELATED_QUERIES) for i, widget := range explore { log.Printf("Widget %d: ID=%s, Title=%s, Token=%s", i, widget.ID, widget.Title, widget.Token[:20]+"...") } } ``` -------------------------------- ### Enable Debugging Source: https://github.com/groovili/gogtrends/blob/master/README.md To view request-response details, enable debugging by calling gogtrends.Debug(true). ```go gogtrends.Debug(true) ``` -------------------------------- ### Handle gogtrends Errors Source: https://context7.com/groovili/gogtrends/llms.txt Demonstrates how to handle specific error types provided by the library, such as invalid categories, failed requests, and widget type mismatches. ```go package main import ( "context" "errors" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Handle invalid category error _, err := gogtrends.Realtime(ctx, "EN", "US", "invalid_category") if errors.Is(err, gogtrends.ErrInvalidCategory) { log.Println("Invalid category provided") log.Printf("Valid categories: %v", gogtrends.TrendsCategories()) } // Handle widget type mismatch explore, _ := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ {Keyword: "test", Geo: "US", Time: "today 12-m"}, }, Category: 0, Property: "", }, "EN") // Trying to use wrong widget type // explore[1] is GEO_MAP, not TIMESERIES _, err = gogtrends.InterestOverTime(ctx, explore[1], "EN") if errors.Is(err, gogtrends.ErrInvalidWidgetType) { log.Println("Wrong widget type - use explore[0] for InterestOverTime") } // Handle request failures gracefully _, err = gogtrends.Daily(ctx, "EN", "INVALID_LOCATION") if errors.Is(err, gogtrends.ErrRequestFailed) { log.Println("Request failed - check location code") } } ``` -------------------------------- ### Retrieve Interest Over Time Data Source: https://context7.com/groovili/gogtrends/llms.txt Fetches interest data points over time for chart visualization. Requires the TIMESERIES widget obtained from the Explore method. Ensure the 'explore' variable contains the correct widget. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // First, get explore widgets explore, err := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ { Keyword: "Docker", Geo: "US", Time: "today 3-m", // Last 3 months }, }, Category: 31, Property: "", }, "EN") if err != nil { log.Fatal(err) } // Get interest over time using first widget (TIMESERIES) timelineData, err := gogtrends.InterestOverTime(ctx, explore[0], "EN") if err != nil { log.Fatal(err) } for _, point := range timelineData { log.Printf("Time: %s, Value: %d, Formatted: %s", point.FormattedTime, point.Value[0], point.FormattedValue[0]) } // Output example: // Time: Jan 7 – 13, 2024, Value: 75, Formatted: 75 // Time: Jan 14 – 20, 2024, Value: 82, Formatted: 82 } ``` -------------------------------- ### Fetch Realtime Trends Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves real-time trending stories with articles and sources. Requires user interface language, location, and category. ```go realtimeTrends, err := gogtrends.Realtime(ctx, "en-US", "US", "all") ``` -------------------------------- ### Retrieve Related Topics and Queries Source: https://context7.com/groovili/gogtrends/llms.txt Fetches related topics and queries for a keyword using the Explore and Related methods. Requires specifying the widget index for related topics (2) and queries (3). ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // First, get explore widgets explore, err := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ { Keyword: "Python", Geo: "US", Time: "today 12-m", }, }, Category: 31, Property: "", }, "EN") if err != nil { log.Fatal(err) } // Get related topics using third widget (RELATED_TOPICS) relatedTopics, err := gogtrends.Related(ctx, explore[2], "EN") if err != nil { log.Fatal(err) } log.Println("Related Topics:") for _, topic := range relatedTopics { log.Printf(" Topic: %s (%s), Value: %s", topic.Topic.Title, topic.Topic.Type, topic.FormattedValue) } // Get related queries using fourth widget (RELATED_QUERIES) relatedQueries, err := gogtrends.Related(ctx, explore[3], "EN") if err != nil { log.Fatal(err) } log.Println("Related Queries:") for _, query := range relatedQueries { log.Printf(" Query: %s, Value: %s", query.Query, query.FormattedValue) } // Output example: // Related Topics: // Topic: Python (Programming language), Value: 100 // Topic: Pandas (Software), Value: 45 // Related Queries: // Query: python tutorial, Value: 100 // Query: python download, Value: 78 } ``` -------------------------------- ### Fetch Related Topics/Queries Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves related topics or queries using an ExploreWidget. Supports two types of widgets. Requires the widget and user interface language. ```go rankedKeywords, err := gogtrends.Related(ctx, widget, "en-US") ``` -------------------------------- ### Enable gogtrends Debug Mode Source: https://context7.com/groovili/gogtrends/llms.txt Enable debug logging to view detailed request-response information for troubleshooting API calls. ```go package main import "github.com/groovili/gogtrends" func main() { // Enable debug logging gogtrends.Debug(true) // All subsequent API calls will log request/response details } ``` -------------------------------- ### Search Related Keywords/Topics Source: https://github.com/groovili/gogtrends/blob/master/README.md Finds up to 5 related keywords or topics for a given search word. Requires the search word and user interface language. ```go relatedKeywords, err := gogtrends.Search(ctx, "golang", "en-US") ``` -------------------------------- ### Google Trends Time Period Formats Source: https://context7.com/groovili/gogtrends/llms.txt Demonstrates various formats for specifying date ranges in the `Time` field of `ComparisonItem`. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Different time period examples timeFormats := []string{ "now 1-H", // Past hour "now 4-H", // Past 4 hours "now 1-d", // Past day "now 7-d", // Past 7 days "today 1-m", // Past month "today 3-m", // Past 3 months "today 12-m", // Past 12 months "today 5-y", // Past 5 years "all", // All time (2004 - present) "2023-01-01 2023-12-31", // Custom date range } // Example with custom date range explore, err := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ { Keyword: "ChatGPT", Geo: "", // Worldwide (empty geo) Time: "2023-01-01 2023-12-31", }, }, Category: 0, // All categories Property: "", // Web Search (alternatives: "youtube", "news", "images", "froogle") }, "EN") if err != nil { log.Fatal(err) } log.Printf("Widgets retrieved: %d", len(explore)) } ``` -------------------------------- ### Fetch Interest Over Time Data Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves data points for an interest over time chart using an ExploreWidget. Requires the widget and user interface language. ```go timelineData, err := gogtrends.InterestOverTime(ctx, widget, "en-US") ``` -------------------------------- ### Search for Related Keywords Source: https://context7.com/groovili/gogtrends/llms.txt Searches for topics and keywords related to a given search term and language. It returns up to 5 results, including the topic type and a machine ID (Mid) for more specific future queries. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Search for topics related to "Go" keywords, err := gogtrends.Search(ctx, "Go", "EN") if err != nil { log.Fatal(err) } for _, kw := range keywords { log.Printf("Title: %s, Type: %s, Mid: %s", kw.Title, kw.Type, kw.Mid) } // Output examples: // Title: Go, Type: Programming language, Mid: /m/09gbxjr // Title: Go, Type: Board game, Mid: /m/03g4vh // Use the Mid (machine ID) for more specific explore queries var programmingKeyword string for _, kw := range keywords { if kw.Type == "Programming language" { programmingKeyword = kw.Mid // e.g., "/m/09gbxjr" break } } log.Printf("Programming language Mid: %s", programmingKeyword) } ``` -------------------------------- ### Fetch Interest By Location Data Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves geographical data for interest by location using an ExploreWidget. Requires the widget and user interface language. ```go geoMapData, err := gogtrends.InterestByLocation(ctx, widget, "en-US") ``` -------------------------------- ### Explore Widgets for Advanced Trends Source: https://github.com/groovili/gogtrends/blob/master/README.md Fetches widgets containing tokens and request information for specific trend methods like InterestOverTime, InterestByLocation, and Related. Requires an ExploreRequest struct and user interface language. ```go exploreReq := &gogtrends.ExploreRequest{...} widgets, err := gogtrends.Explore(ctx, exploreReq, "en-US") ``` -------------------------------- ### Compare Keyword Interests Source: https://github.com/groovili/gogtrends/blob/master/README.md Compares the interest trends for multiple keywords within a specified category and time frame. Requires a context and a configured ExploreRequest with multiple ComparisonItems. ```go // Compare keywords interest compare, err := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ { Keyword: "Go", Geo: "US", Time: "today 12-m", }, { Keyword: "Python", Geo: "US", Time: "today 12-m", }, { Keyword: "PHP", Geo: "US", Time: "today 12-m", }, }, Category: 31, // Programming category Property: "", }, "EN") ``` -------------------------------- ### Compare Keyword Interest Over Time and by Location Source: https://context7.com/groovili/gogtrends/llms.txt Compares interest trends for multiple keywords across different regions and over time. Utilizes the Explore, InterestOverTime, and InterestByLocation methods. Helper methods like GetWidgetsByType can filter widgets by their ID. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Compare programming languages compare, err := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ { Keyword: "Go", Geo: "US", Time: "today 12-m", }, { Keyword: "Python", Geo: "US", Time: "today 12-m", }, { Keyword: "Rust", Geo: "US", Time: "today 12-m", }, }, Category: 31, // Programming category Property: "", }, "EN") if err != nil { log.Fatal(err) } // Get comparative interest over time timelineData, err := gogtrends.InterestOverTime(ctx, compare[0], "EN") if err != nil { log.Fatal(err) } for _, point := range timelineData { // Value array contains interest for each keyword in order log.Printf("Time: %s, Go: %d, Python: %d, Rust: %d", point.FormattedTime, point.Value[0], // Go point.Value[1], // Python point.Value[2]) // Rust } // Get comparative geographic interest geoData, err := gogtrends.InterestByLocation(ctx, compare[1], "EN") if err != nil { log.Fatal(err) } for _, geo := range geoData { log.Printf("Location: %s, Go: %d, Python: %d, Rust: %d", geo.GeoName, geo.Value[0], geo.Value[1], geo.Value[2]) } // Use helper methods to get widgets by type timeseriesWidgets := compare.GetWidgetsByType(gogtrends.IntOverTimeWidgetID) geoWidgets := compare.GetWidgetsByType(gogtrends.IntOverRegionID) log.Printf("Timeseries widgets: %d, Geo widgets: %d", len(timeseriesWidgets), len(geoWidgets)) } ``` -------------------------------- ### Fetch Daily Trends Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves daily trending searches, ordered by date. Requires user interface language and location. ```go dailyTrends, err := gogtrends.Daily(ctx, "en-US", "US") ``` -------------------------------- ### Fetch Daily Trends Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves daily trending searches for a specified language and country. Requires a background context. ```go // Daily trends ctx := context.Background() dailySearches, err := gogtrends.Daily(ctx, "EN", "US") ``` -------------------------------- ### Retrieve Realtime Trending Stories Source: https://context7.com/groovili/gogtrends/llms.txt Fetches real-time trending stories for a given language, country, and category. It also shows how to list available categories and retrieve trends for a specific category like technology/science. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Get available categories categories := gogtrends.TrendsCategories() log.Printf("Available categories: %v", categories) // Output: map[all:all b:business e:entertainment h:main news m:health s:sport t:science and technics] // Get realtime trends for all categories in the US realtimeTrends, err := gogtrends.Realtime(ctx, "EN", "US", "all") if err != nil { log.Fatal(err) } for _, story := range realtimeTrends { log.Printf("Story: %s", story.Title) for _, article := range story.Articles { log.Printf(" Source: %s - %s", article.Source, article.Title) } } // Get technology/science specific trends techTrends, err := gogtrends.Realtime(ctx, "EN", "US", "t") if err != nil { log.Fatal(err) } log.Printf("Tech trends count: %d", len(techTrends)) } ``` -------------------------------- ### Retrieve Interest by Location Data Source: https://context7.com/groovili/gogtrends/llms.txt Fetches geographic interest data with geo codes and interest values for map visualization. Requires the GEO_MAP widget from the Explore method. Ensure the 'explore' variable contains the correct widget. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // First, get explore widgets explore, err := gogtrends.Explore(ctx, &gogtrends.ExploreRequest{ ComparisonItems: []*gogtrends.ComparisonItem{ { Keyword: "React", Geo: "US", Time: "today 12-m", }, }, Category: 31, Property: "", }, "EN") if err != nil { log.Fatal(err) } // Get interest by location using second widget (GEO_MAP) geoData, err := gogtrends.InterestByLocation(ctx, explore[1], "EN") if err != nil { log.Fatal(err) } for _, geo := range geoData { log.Printf("Location: %s (%s), Interest: %d", geo.GeoName, geo.GeoCode, geo.Value[0]) } // Output example: // Location: California (US-CA), Interest: 100 // Location: Washington (US-WA), Interest: 89 // Location: New York (US-NY), Interest: 76 } ``` -------------------------------- ### Available Trends Categories Source: https://github.com/groovili/gogtrends/blob/master/README.md Provides a map of available categories for real-time trends. ```APIDOC ## Available Trends Categories ### Description Returns a map where keys are category identifiers and values are display names for categories usable with the `Realtime` trends method. ### Method GET ### Endpoint /trends/categories ### Parameters None ### Response #### Success Response (200) - **map[string]string** - A map of available categories. #### Response Example ```json { "all": "All Categories", "h": "Headlines", "e": "Business & Industrial", "m": "Science & Technology" } ``` ``` -------------------------------- ### Explore Widgets API Source: https://github.com/groovili/gogtrends/blob/master/README.md Generates widgets containing tokens and request information for specific trend analysis methods like InterestOverTime, InterestByLocation, and Related. ```APIDOC ## Explore Widgets API ### Description This method generates widgets that contain necessary tokens and request parameters for subsequent calls to `InterestOverTime`, `InterestByLocation`, and `Related` methods. It supports single or multiple item comparisons. ### Method POST ### Endpoint /trends/explore ### Parameters #### Request Body - **r** (*ExploreRequest) - Required - An object representing the search or comparison items. This struct can include multiple categories and locations. - **keywordRequest** (*KeywordRequest) - Optional - Request for keyword-based exploration. - **categoryRequest** (*CategoryRequest) - Optional - Request for category-based exploration. - **timeRange** (string) - Optional - The time range for the exploration (e.g., "today 5-y"). - **comparisonItems** ([]*ComparisonItem) - Optional - Items to compare. - **keyword** (string) - Required - The keyword or topic to compare. - **geo** (string) - Optional - The geographic location for comparison. - **time** (string) - Optional - The time range for comparison. - **hl** (string) - Required - User interface language. ### Request Example ```json { "r": { "keywordRequest": { "keywords": ["Go programming", "Python programming"], "geo": "US", "time": "today 5-y" } }, "hl": "en-US" } ``` ### Response #### Success Response (200) - **[]*ExploreWidget** (array) - A list of explore widgets, each containing a unique token and request details for specific trend analysis. #### Response Example ```json [ { "token": "example_token_1", "request": { "keywords": ["Go programming"], "geo": "US", "time": "today 5-y" } }, { "token": "example_token_2", "request": { "keywords": ["Python programming"], "geo": "US", "time": "today 5-y" } } ] ``` ``` -------------------------------- ### Interest Over Time API Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves interest over time data points for a given widget. ```APIDOC ## Interest Over Time API ### Description Fetches data points representing the interest over time for a specific query or topic, as defined by an `ExploreWidget`. ### Method POST ### Endpoint /trends/interestovertime ### Parameters #### Request Body - **w** (*ExploreWidget) - Required - The widget obtained from the `Explore` method, containing the necessary token and request parameters. - **hl** (string) - Required - User interface language. ### Request Example ```json { "w": { "token": "example_token_1", "request": { "keywords": ["Go programming"], "geo": "US", "time": "today 5-y" } }, "hl": "en-US" } ``` ### Response #### Success Response (200) - **[]*Timeline** (array) - A list of timeline data points, each with a timestamp and an interest value. #### Response Example ```json [ { "time": "2023-01-01T00:00:00Z", "value": [10] }, { "time": "2023-01-02T00:00:00Z", "value": [12] } ] ``` ``` -------------------------------- ### Retrieve Google Trends Categories Source: https://context7.com/groovili/gogtrends/llms.txt Fetches the complete tree of available categories for filtering explore queries. Results are cached after the first call. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Get categories tree (cached after first call) categories, err := gogtrends.ExploreCategories(ctx) if err != nil { log.Fatal(err) } // Print top-level categories log.Printf("Root: %s (ID: %d)", categories.Name, categories.ID) for _, cat := range categories.Children { log.Printf("Category: %s (ID: %d)", cat.Name, cat.ID) // Print subcategories for _, subcat := range cat.Children { log.Printf(" Subcategory: %s (ID: %d)", subcat.Name, subcat.ID) } } // Output example: // Category: Arts & Entertainment (ID: 3) // Category: Computers & Electronics (ID: 5) // Subcategory: Computer Hardware (ID: 30) // Subcategory: Programming (ID: 31) // Category: Science (ID: 174) } ``` -------------------------------- ### Interest By Location API Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves interest by location data, providing geo codes and interest values for a given widget. ```APIDOC ## Interest By Location API ### Description Fetches data representing the interest in a query or topic across different geographic locations, as defined by an `ExploreWidget`. ### Method POST ### Endpoint /trends/interestbylocation ### Parameters #### Request Body - **w** (*ExploreWidget) - Required - The widget obtained from the `Explore` method, containing the necessary token and request parameters. - **hl** (string) - Required - User interface language. ### Request Example ```json { "w": { "token": "example_token_1", "request": { "keywords": ["Go programming"], "geo": "US", "time": "today 5-y" } }, "hl": "en-US" } ``` ### Response #### Success Response (200) - **[]*GeoMap** (array) - A list of geographic data points, each with a geo code and an associated interest value. #### Response Example ```json [ { "geo": { "country": "US", "region": "CA" }, "value": [50] }, { "geo": { "country": "US", "region": "NY" }, "value": [45] } ] ``` ``` -------------------------------- ### Explore Locations Tree API Source: https://github.com/groovili/gogtrends/blob/master/README.md Fetches a tree structure of available locations for use in explore and comparison requests. Data is cached after the first call. ```APIDOC ## Explore Locations Tree API ### Description Retrieves a hierarchical tree structure of available locations that can be used for exploration and comparison purposes. This data is cached locally after the initial fetch. ### Method GET ### Endpoint /trends/explore/locations ### Parameters None ### Response #### Success Response (200) - **ExploreLocTree** - An object representing the location tree structure. #### Response Example ```json { "name": "World", "id": "0", "subLocations": [ { "name": "United States", "id": "US", "subLocations": [ { "name": "California", "id": "US-CA", "subLocations": [] } ] } ] } ``` ``` -------------------------------- ### Realtime Trends API Source: https://github.com/groovili/gogtrends/blob/master/README.md Fetches real-time trending searches with associated articles and sources. Requires a category parameter. ```APIDOC ## Realtime Trends API ### Description Retrieves real-time trending searches, including associated articles and sources. This method requires a specific category. ### Method GET ### Endpoint /trends/realtime ### Parameters #### Query Parameters - **hl** (string) - Required - User interface language. - **loc** (string) - Required - Uppercase location (geo) country code (e.g., "US"). - **cat** (string) - Required - Lowercase category for real-time trends (e.g., "all"). Available categories can be found using `TrendsCategories()`. ### Response #### Success Response (200) - **[]*TrendingStory** (array) - A list of real-time trending stories, each with title, articles, and sources. #### Response Example ```json [ { "title": "Realtime Trend Example", "articles": [ { "title": "Article Title", "url": "http://example.com/article" } ], "sources": [ { "title": "Source Name", "url": "http://example.com/source" } ] } ] ``` ``` -------------------------------- ### Retrieve Daily Trending Searches Source: https://context7.com/groovili/gogtrends/llms.txt Fetches daily trending searches for a specified language and country. Logs trend titles and traffic information, along with associated articles. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Get daily trends for United States in English dailySearches, err := gogtrends.Daily(ctx, "EN", "US") if err != nil { log.Fatal(err) } for _, search := range dailySearches { log.Printf("Trend: %s, Traffic: %s", search.Title.Query, search.FormattedTraffic) // Access related articles for _, article := range search.Articles { log.Printf(" Article: %s (%s)", article.Title, article.Source) } } } ``` -------------------------------- ### Daily Trends API Source: https://github.com/groovili/gogtrends/blob/master/README.md Fetches daily trending searches, ordered by date and associated articles. ```APIDOC ## Daily Trends API ### Description Retrieves a list of daily trending searches, sorted in descending order by date, along with related articles. ### Method GET ### Endpoint /trends/daily ### Parameters #### Query Parameters - **hl** (string) - Required - User interface language. - **loc** (string) - Required - Uppercase location (geo) country code (e.g., "US"). ### Response #### Success Response (200) - **[]*TrendingSearch** (array) - A list of trending search objects, each containing details about the trend and associated articles. #### Response Example ```json [ { "title": "Example Trend Title", "articles": [ { "title": "Article Title", "url": "http://example.com/article" } ] } ] ``` ``` -------------------------------- ### Related Topics/Queries API Source: https://github.com/groovili/gogtrends/blob/master/README.md Retrieves related topics or queries based on a given widget. ```APIDOC ## Related Topics/Queries API ### Description Fetches a list of related topics or queries, supporting two types of widgets, as defined by an `ExploreWidget`. ### Method POST ### Endpoint /trends/related ### Parameters #### Request Body - **w** (*ExploreWidget) - Required - The widget obtained from the `Explore` method, containing the necessary token and request parameters. - **hl** (string) - Required - User interface language. ### Request Example ```json { "w": { "token": "example_token_1", "request": { "keywords": ["Go programming"], "geo": "US", "time": "today 5-y" } }, "hl": "en-US" } ``` ### Response #### Success Response (200) - **[]*RankedKeyword** (array) - A list of ranked keywords or topics, each with a value and a link. #### Response Example ```json [ { "rankedKeyword": "Related Query 1", "value": 100, "link": "/trends/explore?q=Related+Query+1" }, { "rankedKeyword": "Related Query 2", "value": 90, "link": "/trends/explore?q=Related+Query+2" } ] ``` ``` -------------------------------- ### Explore Categories Tree API Source: https://github.com/groovili/gogtrends/blob/master/README.md Fetches a tree structure of available categories for use in explore and comparison requests. Data is cached after the first call. ```APIDOC ## Explore Categories Tree API ### Description Retrieves a hierarchical tree structure of available categories that can be used for exploration and comparison purposes. This data is cached locally after the initial fetch. ### Method GET ### Endpoint /trends/explore/categories ### Parameters None ### Response #### Success Response (200) - **ExploreCatTree** - An object representing the category tree structure. #### Response Example ```json { "name": "All", "id": "all", "subCategories": [ { "name": "Business", "id": "e", "subCategories": [] }, { "name": "Entertainment", "id": "h", "subCategories": [ { "name": "Movies", "id": "e_1", "subCategories": [] } ] } ] } ``` ``` -------------------------------- ### Search Related Topics/Keywords API Source: https://github.com/groovili/gogtrends/blob/master/README.md Finds up to 5 related topics or keywords for a given search term. ```APIDOC ## Search Related Topics/Keywords API ### Description Returns a list of up to 5 related topics or keywords based on the provided search word. ### Method GET ### Endpoint /trends/search ### Parameters #### Query Parameters - **word** (string) - Required - The search term to find related topics for. - **hl** (string) - Required - User interface language. ### Response #### Success Response (200) - **[]*KeywordTopic** (array) - A list of related keyword or topic objects. #### Response Example ```json [ { "topic": "Related Topic 1", "query": "related topic 1 query" }, { "topic": "Related Topic 2", "query": "related topic 2 query" } ] ``` ``` -------------------------------- ### Retrieve Google Trends Locations Source: https://context7.com/groovili/gogtrends/llms.txt Fetches the complete tree of available locations (geo codes) for filtering explore queries. Results are cached after the first call. ```go package main import ( "context" "log" "github.com/groovili/gogtrends" ) func main() { ctx := context.Background() // Get locations tree (cached after first call) locations, err := gogtrends.ExploreLocations(ctx) if err != nil { log.Fatal(err) } // Print countries and their regions for _, country := range locations.Children { log.Printf("Country: %s (Code: %s)", country.Name, country.ID) // Print regions/states for each country for _, region := range country.Children { log.Printf(" Region: %s (Code: %s)", region.Name, region.ID) } } // Output example: // Country: United States (Code: US) // Region: Alabama (Code: US-AL) // Region: California (Code: US-CA) // Country: United Kingdom (Code: GB) // Region: England (Code: GB-ENG) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.