The google_trends_explore source is designed to retrieve Google Trends results.
Due to ongoing issues, the scraped data may not be 100% accurate compared to direct usage on Google Trends via web browsers. Please use it with caution and be aware of potential discrepancies.
Request samples
In this example, we make a request to get trends results for a search term adidas between the 1st of January, 2021 and the 2nd of February, 2022, and set the category to "Arts & Entertainment" (category id: 3).
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
namespace OxyApi
{
class Program
{
static async Task Main()
{
const string Username = "USERNAME";
const string Password = "PASSWORD";
var parameters = new {
source = "google_trends_explore",
query = "adidas",
context = new dynamic [] {
new { key = "date_from", value = "2021-01-01" },
new { key = "date_to", value = "2022-02-02" },
new { key = "category_id", value = 3 }
}
};
var client = new HttpClient();
Uri baseUri = new Uri("https://realtime.oxylabs.io");
client.BaseAddress = baseUri;
var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/v1/queries");
requestMessage.Content = JsonContent.Create(parameters);
var authenticationString = $"{Username}:{Password}";
var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(authenticationString));
requestMessage.Headers.Add("Authorization", "Basic " + base64EncodedAuthenticationString);
var response = await client.SendAsync(requestMessage);
var contents = await response.Content.ReadAsStringAsync();
Console.WriteLine(contents);
}
}
}
package org.example;
import okhttp3.*;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.concurrent.TimeUnit;
public class Main implements Runnable {
private static final String AUTHORIZATION_HEADER = "Authorization";
public static final String USERNAME = "USERNAME";
public static final String PASSWORD = "PASSWORD";
public void run() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("source", "google_trends_explore");
jsonObject.put("query", "adidas");
jsonObject.put("context", new JSONArray()
.put(new JSONObject().put("key", "date_from").put("value", "2021-01-01"))
.put(new JSONObject().put("key", "date_to").put("value", "2022-02-02"))
.put(new JSONObject().put("key", "category_id").put("value", 3))
);
Authenticator authenticator = (route, response) -> {
String credential = Credentials.basic(USERNAME, PASSWORD);
return response
.request()
.newBuilder()
.header(AUTHORIZATION_HEADER, credential)
.build();
};
var client = new OkHttpClient.Builder()
.authenticator(authenticator)
.readTimeout(180, TimeUnit.SECONDS)
.build();
var mediaType = MediaType.parse("application/json; charset=utf-8");
var body = RequestBody.create(jsonObject.toString(), mediaType);
var request = new Request.Builder()
.url("https://realtime.oxylabs.io/v1/queries")
.post(body)
.build();
try (var response = client.newCall(request).execute()) {
if (response.body() != null) {
try (var responseBody = response.body()) {
System.out.println(responseBody.string());
}
}
} catch (Exception exception) {
System.out.println("Error: " + exception.getMessage());
}
System.exit(0);
}
public static void main(String[] args) {
new Thread(new Main()).start();
}
}
We use synchronous integration method in our examples. If you would like to use or asynchronous integration, refer to the section.
Request parameter values
Generic
Basic setup and customization options for scraping Google Trends results.
Parameter
Description
Default Value
source
Sets the scraper.
google_trends_explore
query
UTF-encoded keyword.
-
callback_url
-
user_agent_type
desktop
geo_location
The geographical location that the result should be adapted for. With Google Trends: Explore, we accept 2-letter ISO country codes as geo_location parameter values.
-
- mandatory parameter
Filtering
Advanced options for tailoring and refining the search context.
Parameter
Description
Default Value
context:
search_type
Lets you set the search type (one of the options on Google Trends GUI). Possible values: web_search, image_search, google_shopping, youtube_search.
web_search
context:
date_from
The lower date bracket. Format: YYYY-MM-DD. Oldest possible date: 2004-01-01.
-
context:
date_to
The upper date bracket. Format: YYYY-MM-DD. Oldest possible date: 2004-01-01.
-
context:
category_id
-
Context parameters
All context parameters should be added to the context array as objects with key and value pairs, e.g.: