| [ Web Proxy ] |
| Viewing: https://serpapi.com/integrations/cpp | [Back] [Original] |
Choose the plan that suits you best.
Find the right data solutions tailored to your market.
Automate your projects with structured SERP data.
Start integration with your preferred language.
Dive deeper into our advanced features.
Explore company information and helpful guides.
C++
Official SDK installation
serpapi_dep = dependency("serpapi")
Code to integrate
Integrate search data into your C++ application. This library is the official wrapper for SerpApi.
SerpApi supports Google, Google Maps, Google Shopping, Baidu, Yandex, Yahoo, eBay, App Stores, and more.
C++17 and meson are required.
Install RapidJSON before configuring the build:
# macOS
brew install rapidjson
# Debian/Ubuntu Linux
sudo apt update && sudo apt install -y rapidjson-dev
Download and extract the latest release:
curl -sL https://github.com/serpapi/serpapi-cpp/archive/refs/tags/v0.5.0.tar.gz | tar xz
cd serpapi-0.5.0
meson setup build
meson compile -C build
sudo meson install -C build
Tests are disabled by default for release builds. To build and run tests with Meson, install GoogleTest and configure with -Dtests=true.
Add the dependency to your meson.build:
serpapi_dep = dependency('serpapi')
Or if you are using it as a subproject:
serpapi_proj = subproject('serpapi')
serpapi_dep = serpapi_proj.get_variable('libserpapi_dep')
#include <iostream>
#include <map>
#include <string>
#include <serpapi.hpp>
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>
int main() {
const char* env_p = std::getenv("SERPAPI_KEY");
if (!env_p) return 1;
std::string apiKey(env_p);
std::map<std::string, std::string> default_parameter;
default_parameter["api_key"] = apiKey;
default_parameter["engine"] = "google";
serpapi::Client client(default_parameter);
std::map<std::string, std::string> parameter;
parameter["q"] = "coffee";
parameter["location"] = "Austin,TX";
rapidjson::Document d = client.search(parameter);
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
d.Accept(writer);
std::cout << "\nINFO: " << buffer.GetString() << std::endl;
return 0;
}
This example runs a search for "coffee" on Google. It then returns the results as a RapidJSON Document. See the playground to generate your own code, or check out our local examples.
#include <serpapi.hpp>
// serpapi client created with default parameters
std::map<std::string, std::string> default_params = {
{"api_key", "secret_key"},
{"engine", "google"}
};
serpapi::Client client(default_params);
// search query overview (more fields available depending on search engine)
std::map<std::string, std::string> params = {
{"engine", "google"},
{"q", "Coffee"},
{"location", "Portland,Oregon,United States"},
{"device", "desktop"},
{"hl", "en"},
{"gl", "us"}
};
// formatted search results as a RapidJSON Document
rapidjson::Document results = client.search(params);
// raw search engine html as a String
std::string raw_html = client.html(params);
// raw search engine results as Markdown String
std::string raw_markdown = client.markdown(params);
std::map<std::string, std::string> default_parameter = {};
serpapi::Client client(default_parameter);
std::map<std::string, std::string> parameter;
parameter["limit"] = "3";
parameter["q"] = "Austin";
rapidjson::Document doc = client.location(parameter);
const rapidjson::Value& list = doc.GetArray();
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
list.Accept(writer);
std::cout << buffer.GetString() << std::endl;
It prints the first 3 locations matching Austin (Texas, Texas, Rochester).
NOTE: api_key is not required for this endpoint.
This API allows retrieving previous search results.
serpapi::Client client({{"api_key", "secret_api_key"}, {"engine", "google"}});
rapidjson::Document results = client.search({{"q", "Coffee"}, {"location", "Portland"}});
std::string search_id = results["search_metadata"]["id"].GetString();
// Now let's retrieve the previous search results from the archive.
rapidjson::Document archived_results = client.search_archive(search_id);
serpapi::Client client({{"api_key", "secret_api_key"}});
rapidjson::Document account_info = client.account();
Search API features non-blocking search using the option: async=true.
#include <serpapi.hpp>
#include <rapidjson/document.h>
#include <iostream>
int main() {
serpapi::Client client({{"api_key", "YOUR_API_KEY"}, {"engine", "google"}});
std::map<std::string, std::string> parameter;
parameter["q"] = "coffee";
parameter["async"] = "true";
rapidjson::Document d = client.search(parameter);
std::string id = d["search_metadata"]["id"].GetString();
// You can later retrieve the results using search_archive
rapidjson::Document results = client.search_archive(id);
return 0;
}
C++ versions validated by Github Actions:
rake lint
rake test
rake coverage
Generated with rake coverage (requires SERPAPI_KEY set to exercise the live API tests):
classDiagram
Application *-- serpapi
serpapi *-- Client
class Client {
engine String
api_key String
parameter map
search() Document
html() String
markdown() String
location() Document
search_archive() Document
account() Document
}
We use GitHub Actions for continuous integration.
Set your secret API key in your shell before running tests.
export SERPAPI_KEY="your_secret_key"
Check code quality using Lint.
rake lint
Run tests.
rake test
env SERPAPI_KEY=SERPAPI_KEY docker run --rm -it -e SERPAPI_KEY --workdir /tmp/serpapi -v $PWD:/tmp/serpapi conanio/gcc10 make install_linux reset all
rake install:applerake install:linuxrake setup
rake build
rake example
You are in good company. Join them.
We value full transparency and painful honesty both in our internal and external communications. We believe a world with complete and open transparency is a better world.
Built with love in Austin, TX. 2026 SerpApi, LLC.
| Web Proxy Viewer | New URL | Original Page |