🐍 Python Intermediate Featured

Auto-Post Pinterest Pins with Python

Learn how to automate Pinterest uploads with the Pinterest API and cron job scheduling.

59 views 15 mins Admin 1 month ago

About This Script

This script demonstrates how to automatically post pins to Pinterest using the Pinterest API. Perfect for content creators and marketers who want to schedule their pins in advance.

Features:

  • Authenticate with Pinterest API
  • Upload images from local folder
  • Add descriptions and board selection
  • Schedule posts with cron
Source Code
#!/usr/bin/env python3
import requests
import os
from dotenv import load_dotenv

load_dotenv()

# Pinterest API Configuration
ACCESS_TOKEN = os.getenv("PINTEREST_ACCESS_TOKEN")
BOARD_ID = os.getenv("PINTEREST_BOARD_ID")

def create_pin(image_url, title, description, link):
    url = "https://api.pinterest.com/v5/pins"
    
    headers = {
        "Authorization": f"Bearer {ACCESS_TOKEN}",
        "Content-Type": "application/json"
    }
    
    data = {
        "board_id": BOARD_ID,
        "title": title,
        "description": description,
        "link": link,
        "media_source": {
            "source_type": "image_url",
            "url": image_url
        }
    }
    
    response = requests.post(url, json=data, headers=headers)
    
    if response.status_code == 201:
        print(f"✅ Pin created successfully: {title}")
        return response.json()
    else:
        print(f"❌ Error: {response.status_code} - {response.text}")
        return None

if __name__ == "__main__":
    # Example usage
    create_pin(
        image_url="https://example.com/image.jpg",
        title="My Automated Pin",
        description="This pin was posted automatically using Python!",
        link="https://integratescript.com"
    )
Requirements
Pinterest API credentials, Python 3.8+, requests library
Quick Actions
More in Automation Scripts