FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
serpapi-java/src/test/java/serpapi/SearchArchiveApiTest.java at master · serpapi/serpapi-java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
serpapi
/
serpapi-java
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
8
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-java
/
src
/
test
/
java
/
serpapi
/
SearchArchiveApiTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (42 loc) · 1.59 KB
Breadcrumbs
serpapi-java
/
src
/
test
/
java
/
serpapi
/
SearchArchiveApiTest.java
Copy path
File metadata and controls
51 lines (42 loc) · 1.59 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
49
50
51
package
serpapi
;
import
com
.
google
.
gson
.
JsonObject
;
import
com
.
google
.
gson
.
JsonPrimitive
;
import
org
.
junit
.
Test
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Map
;
import
static
org
.
junit
.
Assert
.*;
/**
* Test SerpApi.searchArchive() method.
*/
public
class
SearchArchiveApiTest
{
@
Test
public
void
searchArchive
()
throws
SerpApiException
,
InterruptedException
{
// skip test if no api_key provided
if
(
System
.
getenv
(
"SERPAPI_KEY"
) ==
null
) {
fail
(
"SERPAPI_KEY is not set"
);
}
Map
<
String
,
String
>
parameter
=
new
HashMap
<>();
parameter
.
put
(
"api_key"
,
System
.
getenv
(
"SERPAPI_KEY"
));
parameter
.
put
(
"q"
,
"Coffee"
);
parameter
.
put
(
"location"
,
"Austin, Texas, United States"
);
parameter
.
put
(
"hl"
,
"en"
);
parameter
.
put
(
"gl"
,
"us"
);
parameter
.
put
(
"google_domain"
,
"google.com"
);
parameter
.
put
(
"safe"
,
"active"
);
parameter
.
put
(
"start"
,
"10"
);
parameter
.
put
(
"device"
,
"desktop"
);
SerpApi
serpapi
=
new
SerpApi
(
parameter
);
JsonObject
results
=
serpapi
.
search
(
parameter
);
assertTrue
(
results
.
getAsJsonArray
(
"organic_results"
).
size
() >
5
);
// now search in the archive
String
id
=
results
.
getAsJsonObject
(
"search_metadata"
).
getAsJsonPrimitive
(
"id"
).
getAsString
();
assertNotNull
(
id
);
System
.
out
.
println
(
"id: "
+
id
);
// wait a bit for cache propagation
Thread
.
sleep
(
100
);
// retrieve search from the archive for free
JsonObject
archive
=
serpapi
.
searchArchive
(
id
);
// compare id and the content should be the same
assertEquals
(
id
,
archive
.
getAsJsonObject
(
"search_metadata"
).
getAsJsonPrimitive
(
"id"
).
getAsString
());
}
}
Back
|
FazBrowse Home
|
New Git URL