2020-04-10 21:48:35 +02:00
< ? php
2020-04-10 21:54:59 +02:00
include_once 'Mastodon.php' ;
$token = 'XXXXX' ; // Token of your Mastodon welcome bot account
$base_url = 'https://botsin.space' ; // URL of your instance (Do not include '/' at the end.)
2022-12-16 16:31:37 +01:00
$privacy = 'private' ; // "direct" means sending welcome message as a private message. The four tiers of visibility for toots are public, unlisted, private, and direct (default)
$language = 'en' ; // en for English, zh for Chinese, de for German etc.
2020-04-10 21:54:59 +02:00
$mastodon = new MastodonAPI ( $token , $base_url );
$curl_file = curl_file_create ( './imageOnServer.jpg' , 'image/jpg' , 'imagename.jpg' );
$body = [
'file' => $curl_file ,
];
$response = $mastodon -> uploadMedia ( $body );
2022-04-20 21:22:02 +02:00
$file_id = $response [ 'id' ];
2020-04-10 21:54:59 +02:00
$statusText = 'This is a status' ;
2022-12-16 16:31:37 +01:00
$status_data = array (
2020-04-10 21:54:59 +02:00
'status' => $statusText ,
2022-12-16 16:31:37 +01:00
'privacy' => $privacy ,
2020-04-10 21:54:59 +02:00
'language' => $language ,
2022-12-16 16:31:37 +01:00
'media_ids[]' => $file_id
);
2020-04-10 21:54:59 +02:00
$mastodon -> postStatus ( $status_data );