Commit 766c4dfa authored by Max Koder's avatar Max Koder


parent cfe5628c
# TootoPHP
TootoPHP is a simple PHP class to retrieve Mastodon toots.
Only the instance and the user name are required.
# Requirements
TootoPHP needs only PHP 5.4 or later.
# Install
To install TootoPHP, you need to get the original **Tooto.php** file, in this repository.
Finally, include the class file.
# Usage
## Create object
Create a new `TootoPHP` object.
You have to put 2 parameters :
- Instance name, like ``
- User name
For example :
$tooto = new TootoPHP('', 'maxk');
## Error checking
TootoPHP offers the possibility of checking whether the parameters provided are correct.
For this, you only need to check the `on_error` attribute :
if ($tooto->on_error) die("Instance or user seem doesn't exist.");
If `on_error` is `true`, there is an error, and you will not be able to retrieve toots or get user's infos.
Else, everything is okay.
## Get author's info
Now you can retrieve basics informations on toots's author, with your object attributes :
$tooto->uri // User's Profile URL
$tooto->name // User's Pseudo
$tooto->email // User's Mastodon Mail
$tooto->summary // User's Summary
$tooto->alternate // User's Profile URL (again)
$tooto->header // User's Header URL
$tooto->avatar // User's Avatar URL
## Retrieve toots
To retrieve toots, the class has a simple function accepting only one optional argument:
$toots = $tooto->getToots(15);
Here, it is indicated that it is desired to retrieve 15 inputs (toots). If no arguments are given, 5 entries will be returned.
All that remains is to exploit the data, returned in an array.
## Array's Exploitation
The returned array thus contains one or more entries, which are themselves associative arrays.
Here is the list of available keys :
- `published` : Timestamp of the date and time the toot was posted
- `updated` : Timestamp of the last modification of the post
- `title` : Toot's title (usually *new status by name* )
- `content` : Post's content
- `pic` : This value is an array containing the URLs of all images posted in the toot.
### Let's see how to use this :
foreach ($toots as $entry) {
echo date("F j, Y, g:i a", $entry['published']);
echo $entry['content'];
foreach ($entry['pic'] as $pic) {
echo '<img src="' . $pic . '" />';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment