FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
serpapi-cpp/example/google_example.cpp at improve/rakefile-flow · serpapi/serpapi-cpp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
serpapi
/
serpapi-cpp
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
serpapi-cpp
/
example
/
google_example.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (38 loc) · 1.4 KB
Breadcrumbs
serpapi-cpp
/
example
/
google_example.cpp
Copy path
File metadata and controls
48 lines (38 loc) · 1.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
include
<
iostream
>
#
include
<
map
>
#
include
<
rapidjson/document.h
>
#
include
<
rapidjson/prettywriter.h
>
#
include
<
rapidjson/stringbuffer.h
>
#
include
<
serpapi.hpp
>
#
include
<
string
>
int
main
() {
const
char
*env_p =
std::getenv
(
"
SERPAPI_KEY
"
);
if
(env_p ==
nullptr
) {
std::cout <<
"
SERPAPI_KEY not set, skipping example
"
<< std::endl;
return
0
;
}
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 <<
"
Search Results:
"
<< std::endl;
std::cout << buffer.
GetString
() << std::endl;
if
(d.
HasMember
(
"
search_metadata
"
) && d[
"
search_metadata
"
].
HasMember
(
"
id
"
)) {
std::string id = d[
"
search_metadata
"
][
"
id
"
].
GetString
();
std::cout <<
"
\n
Archiving search ID:
"
<< id << std::endl;
rapidjson::Document archived = client.
search_archive
(id);
if
(archived.
HasMember
(
"
search_metadata
"
) &&
archived[
"
search_metadata
"
][
"
status
"
] ==
"
Success
"
) {
std::cout <<
"
Successfully retrieved from archive.
"
<< std::endl;
}
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL