如何使用pinterest-node-api进行pin搜索?

acruukt9  于 2023-03-22  发布在  Node.js
关注(0)|答案(1)|浏览(402)
import Pinterest from "pinterest-node-api";
const client = new Pinterest('pina_AMAS3KIWABUBCAA');

  try {
    // Search for pins with the keyword
    const res = await client.request('/pins', {
      method: 'GET',
      params: {
        query: `${keyword} ${modifier}`,
        fields: 'id,note,image'
      }
    });
    const pins = res.data;
  
    // Comment on each pin
    for await (const pin of pins) {
      await client.comment(pin.id, variation);
      console.log(`Commented on pin: https://pinterest.com/pin/${pin.id}`);
    }
  } catch (error) {
    console.error(`Failed to search for or comment on pins. Error: ${error.message}`);
  }

我得到client.request is not a function
我正试图执行一个API调用来搜索全球引脚的关键字。
他们页面上的文档没有给予我太多的信心,因为没有一个例子有效。

ljsrvy3e

ljsrvy3e1#

// Search for pins with the keyword
    const searchUrl = `https://api.pinterest.com/v5/search/pins?query=${encodeURIComponent(search)}&topic_based=true`;
    const res = await fetch(searchUrl, {
      headers: {
        'Authorization': `Bearer ${key}`,
      },
    });

    const pins = (await res.json()).items;

相关问题