-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinterest_queries.js
52 lines (47 loc) · 1.36 KB
/
pinterest_queries.js
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
const axios = require("axios");
const getBoards = async (accessToken) => {
try {
const response = await axios.get("https://api.pinterest.com/v5/boards", {
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
Accept: "application/json",
},
});
all_boards = response.data.items.map((board) => ({
id: board.id,
name: board.name,
description: board.description,
pin_count: board.pin_count,
image: board.media.image_cover_url,
}));
return all_boards;
} catch (error) {
console.error("Error fetching boards:", error.message);
}
};
const getPins = async (accessToken, board_id) => {
try {
const response = await axios.get(
`https://api.pinterest.com/v5/boards/${board_id}/pins`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
Accept: "application/json",
},
params: {
page_size: 10,
},
}
);
const imagePins = response.data.items
.filter((pin) => pin.media.media_type === "image")
.map((pin) => pin.media.images["600x"].url);
// console.log(imagePins);
return imagePins;
} catch (error) {
console.error("Error fetching pins:", error.message);
}
};
module.exports = { getBoards, getPins };