Mastodon-Bot-PHP/examples/media_bot.php

31 lines
984 B
PHP
Raw Normal View History

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.)
$visibility = '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, etc.
$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';
$status_data = [
'status' => $statusText,
'visibility' => $visibility,
'language' => $language,
'media_ids[]' => $file_id,
];
$mastodon->postStatus($status_data);