You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用pinterest-node-api进行Pin搜索时遇client.request未定义问题

Fixing "client.request is not a function" in pinterest-node-api

The error occurs because the pinterest-node-api package does not expose a request method on the client instance. Additionally, if the package's official documentation is broken and examples don't work, relying on this third-party wrapper becomes unreliable. Here are two actionable solutions:

Solution 1: Use the Package's Actual Exposed Methods

If you still want to stick with the package, check its source code (via npm or GitHub) to find valid methods. For example:

  • Searching pins may require a dedicated search method instead of the non-existent request:
    import Pinterest from "pinterest-node-api";
    const client = new Pinterest('pina_AMAS3KIWABUBCAA');
    
    try {
      // Adjust method name based on the package's actual implementation
      const pins = await client.search({
        query: `${keyword} ${modifier}`,
        fields: 'id,note,image'
      });
    
      // Comment on each pin (if the comment method is properly implemented)
      for (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: ${error.message}`);
    }
    

Note: This depends entirely on the package's actual code—if the comment method also fails, the package is likely outdated or poorly maintained.

Solution 2: Call the Official Pinterest API Directly

For long-term reliability, bypass the broken wrapper and interact with the official Pinterest REST API directly using axios or fetch:

Step 1: Install Axios (optional, simplifies HTTP requests)

npm install axios

Step 2: Rewrite the Code

import axios from 'axios';

const accessToken = 'pina_AMAS3KIWABUBCAA';
const baseApiUrl = 'https://api.pinterest.com/v5';

try {
  // Search for pins via official endpoint
  const searchResponse = await axios.get(`${baseApiUrl}/search/pins`, {
    headers: { 'Authorization': `Bearer ${accessToken}` },
    params: {
      query: `${keyword} ${modifier}`,
      fields: 'id,note,image'
    }
  });
  const pins = searchResponse.data.data;

  // Comment on each pin
  for (const pin of pins) {
    await axios.post(
      `${baseApiUrl}/pins/${pin.id}/comments`,
      { text: variation },
      {
        headers: {
          'Authorization': `Bearer ${accessToken}`,
          'Content-Type': 'application/json'
        }
      }
    );
    console.log(`Commented on pin: https://pinterest.com/pin/${pin.id}`);
  }
} catch (error) {
  const errorMessage = error.response?.data?.message || error.message;
  console.error(`Failed to search or comment: ${errorMessage}`);
}

Key Notes:

  • Ensure your access token has the required scopes (pins:read for searching, pins:write for commenting).
  • Official API docs outline endpoint details, rate limits, and scope requirements (no external links provided per restrictions).

内容的提问来源于stack exchange,提问作者chovy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 05:53:17