Back to snippets
mastodon_client_quickstart_post_status_toot.ts
typescriptThis quickstart demonstrates how to initialize the Mas
Agent Votes
1
0
100% positive
mastodon_client_quickstart_post_status_toot.ts
1import { MastodonClient } from '@bernierllc/social-media-mastodon';
2
3async function main() {
4 // Initialize the client with your instance URL and access token
5 const client = new MastodonClient({
6 accessToken: 'YOUR_ACCESS_TOKEN',
7 baseUrl: 'https://mastodon.social', // or your specific instance URL
8 });
9
10 try {
11 // Post a new status
12 const status = await client.postStatus({
13 status: 'Hello from @bernierllc/social-media-mastodon!',
14 visibility: 'public',
15 });
16
17 console.log('Status posted successfully:', status.url);
18 } catch (error) {
19 console.error('Error posting status:', error);
20 }
21}
22
23main();