
本文详解如何基于pinterest官方rest api构建合规、稳定的json接口,实现图钉的自动保存,避免使用selenium等易被封禁的模拟操作方案。
本文详解如何基于pinterest官方rest api构建合规、稳定的json接口,实现图钉的自动保存,避免使用selenium等易被封禁的模拟操作方案。
Pinterest明确禁止未经许可的自动化操作(包括爬虫、鼠标模拟、未授权登录脚本等),其官方文档明确指出:所有第三方集成必须通过 Pinterest Business API,并使用 OAuth 2.0 认证获取用户授权。因此,所谓“自动保存 pins”的合法路径只有一条:构建一个符合规范的 JSON API 服务,后端调用 Pinterest 的 /pins 创建端点(POST https://api.pinterest.com/v3/pins/),而非依赖 Selenium 模拟浏览器行为——后者不仅违反《Pinterest Platform Policy》,还极易触发风控封禁账号,且无法在无头环境中稳定运行。
✅ 正确实践流程如下:
注册开发者应用
登录 Pinterest for Developers,创建新应用,获取 client_id 和 client_secret,并配置重定向 URI(如 https://yourdomain.com/callback)。-
引导用户授权(OAuth 2.0)
构建授权链接:https://www.pinterest.com/oauth/?response_type=code &client_id=YOUR_CLIENT_ID &redirect_uri=https%3A%2F%2Fyourdomain.com%2Fcallback &scope=read_public,write_pins
用户授权后,Pinterest 将 code 返回至你的回调地址。
-
换取访问令牌(Access Token)
使用 code 向 https://api.pinterest.com/v5/oauth/token 发送 POST 请求:curl -X POST "https://api.pinterest.com/v5/oauth/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code" \ -d "code=AUTHORIZATION_CODE" \ -d "redirect_uri=https%3A%2F%2Fyourdomain.com%2Fcallback" \ -d "client_id=YOUR_CLIENT_ID" \ -d "client_secret=YOUR_CLIENT_SECRET"
成功响应将返回 access_token(有效期通常为 1 小时,支持刷新)。
-
调用 Pins API 保存图钉
使用有效 token 向 /v3/pins/ 提交 JSON 数据(注意:v3 是当前稳定版,v5 不支持 pin 创建):POST https://api.pinterest.com/v3/pins/ Authorization: Bearer YOUR_ACCESS_TOKEN Content-Type: application/json { "board_id": "123456789012345678", "note": "Beautiful sunset photo", "link": "https://example.com/photo.jpg", "image_url": "https://example.com/photo.jpg", "title": "Sunset View" }✅ 响应成功将返回 201 Created 及新 Pin 的完整对象。
⚠️ 重要注意事项:
- 不允许批量高频调用:Pinterest 对 /pins/ 接口有严格限流(通常 ≤ 100 次/小时/用户),需实现退避重试逻辑;
- image_url 必须可公开访问且托管于 HTTPS 域名,Pinterest 会主动抓取并校验;
- 个人账户需升级为 Business Account 才能获得 write_pins 权限;
- 避免硬编码 token——生产环境应使用安全存储(如 HashiCorp Vault)+ 短期 token 刷新机制。
总结:真正的自动化不是绕过平台规则,而是尊重其生态设计。一个健壮的 Pinterest JSON API 应以 OAuth 为核心、以业务账号为前提、以 REST 规范为准则。放弃 Selenium 路线,转向官方 API,既是合规要求,更是长期可用性的技术保障。
大量免费API接口:立即使用
涵盖生活服务API、金融科技API、企业工商API、等相关的API接口服务。免费API接口可安全、合规地连接上下游,为数据API应用能力赋能!











