scripting / Scripting-News

I'm starting to use GitHub for work on my blog. Why not? It's got good communication and collaboration tools. Why not hook it up to a blog?
121 stars 10 forks source link

Hello World for Threads #309

Open scripting opened 5 months ago

scripting commented 5 months ago

I asked ChatGPT to write a simple Hello World app for the Threads API.

const axios = require('axios');

// Replace with your API token
const apiToken = 'YOUR_API_TOKEN_HERE';

const postHelloWorld = async () => {
    try {
        const response = await axios.post('https://api.threads.com/v1/posts', {
            content: 'Hello, World!'
        }, {
            headers: {
                'Authorization': `Bearer ${apiToken}`,
                'Content-Type': 'application/json'
            }
        });

        console.log('Post ID:', response.data.id);
        console.log('Post Content:', response.data.content);
    } catch (error) {
        console.error('Error posting to Threads API:', error);
    }
};

postHelloWorld();

I haven't tried running it yet. But maybe you can spot problems like cpinto did.