Using ontologies to fetch Peertube Outbox activities

There are 2 ways to use ontologies:

Luckily, ActivityPhp is packaged with Peertube’s ontology.

So, you just have to set peertube configuration.

If you want to be more permissive (in order to work with all federated ontologies), simply use * parameter.

Fetch Peertube Outbox activities

Below, a complete script to work with Peertube’s objects. It browses all outbox pages, collect all activities and display a list of activities and their videos names.

use ActivityPhp\Server;

/* ------------------------------------------------------------------
 | Use an instance with a PeerTube flavor
   ------------------------------------------------------------------ */

// Create a server instance and allow peertube ontology
$server = new Server([
    'ontologies' => [
        'peertube',
    ]
]);

$handle = 'nickname@example.org';

// Get an actor's outbox as an OrderedCollection
$outbox = $server->outbox($handle);

// Prepare a stack
$pages = [];

// Browse first page
$page = $outbox->getPage($outbox->get()->first);

// Browse all pages and get public actvities
$pages[] = $page;
while ($page->next !== null) {
    $page = $outbox->getPage($page->next);
    $pages[] = $page;
}

// Now we can work with pages
foreach ($pages as $page) {
    foreach ($page->orderedItems as $item) {
        echo sprintf(
            "Type=%s, Name=%s\n",
            $item->type,            // Activity type
            $item->object->name     // Video name
        );
    }
}

Read more


Edit this document on GitHub