0

List following

by
Published Dec 20, 2024

Get a list of who a certain user follows.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * List following
7
 * Get a list of who a certain user follows.
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  bookmark: string | undefined,
12
  page_size: string | undefined,
13
  feed_type:
14
    | "ALL"
15
    | "RANKED"
16
    | "CREATOR_ONLY"
17
    | "RANKED_CREATOR_ONLY"
18
    | undefined,
19
  explicit_following: string | undefined,
20
  ad_account_id: string | undefined,
21
) {
22
  const url = new URL(`https://api.pinterest.com/v5/user_account/following`);
23
  for (const [k, v] of [
24
    ["bookmark", bookmark],
25
    ["page_size", page_size],
26
    ["feed_type", feed_type],
27
    ["explicit_following", explicit_following],
28
    ["ad_account_id", ad_account_id],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47