Edits history of script submission #11367 for ' List trending keywords (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * List trending keywords
     * Get the top trending search keywords among the Pinterest user audience.
     */
    export async function main(
      auth: Pinterest,
      region:
        | "US"
        | "CA"
        | "DE"
        | "FR"
        | "ES"
        | "IT"
        | "DE+AT+CH"
        | "GB+IE"
        | "IT+ES+PT+GR+MT"
        | "PL+RO+HU+SK+CZ"
        | "SE+DK+FI+NO"
        | "NL+BE+LU"
        | "AR"
        | "BR"
        | "CO"
        | "MX"
        | "MX+AR+CO+CL"
        | "AU+NZ",
      trend_type: "growing" | "monthly" | "yearly" | "seasonal",
      interests: string | undefined,
      genders: string | undefined,
      ages: string | undefined,
      include_keywords: string | undefined,
      normalize_against_group: string | undefined,
      limit: string | undefined,
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/trends/keywords/${region}/top/${trend_type}`,
      );
      for (const [k, v] of [
        ["interests", interests],
        ["genders", genders],
        ["ages", ages],
        ["include_keywords", include_keywords],
        ["normalize_against_group", normalize_against_group],
        ["limit", limit],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 537 days ago