-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (55 loc) · 1.57 KB
/
index.js
File metadata and controls
65 lines (55 loc) · 1.57 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const axios = require('axios');
// 1. Configuration
const API_KEY = 'YOUR_RAPIDAPI_KEY_HERE'; // Get this from RapidAPI
const QUERY = 'Blue Ocean';
// 2. Execution Get Images with imageInfo
const optionsOne = {
method: 'GET',
url: 'https://google-images4.p.rapidapi.com/getGoogleImages',
params: {
query: QUERY,
count: '5', // Number of images
imageInfo: 'true' // Returns size and type
},
headers: {
'X-RapidAPI-Key': API_KEY,
'X-RapidAPI-Host': 'google-images4.p.rapidapi.com'
}
};
async function getImagesImageInfo() {
try {
console.log(`Searching for: ${QUERY}...`);
const response = await axios.request(optionsOne);
// Log the first image URL found
const firstImage = response.data.images[0];
console.log('Success! Found image:', firstImage.url);
} catch (error) {
console.error('Error:', error.message);
}
}
// 3. Execution Get Images
const optionsTwo = {
method: 'GET',
url: 'https://google-images4.p.rapidapi.com/getGoogleImages',
params: {
query: QUERY,
count: '5', // Number of images
},
headers: {
'X-RapidAPI-Key': API_KEY,
'X-RapidAPI-Host': 'google-images4.p.rapidapi.com'
}
};
async function getImages() {
try {
console.log(`Searching for: ${QUERY}...`);
const response = await axios.request(optionsTwo);
// Log the first image URL found
const firstImageUrl = response.data.images[0];
console.log('Success! Found image:', firstImageUrl);
} catch (error) {
console.error('Error:', error.message);
}
}
getImagesImageInfo();
getImages();