Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fetch Peertube Outbox activities" Docs is not working (for me) #41

Open
scammo opened this issue Apr 2, 2024 · 3 comments
Open

"Fetch Peertube Outbox activities" Docs is not working (for me) #41

scammo opened this issue Apr 2, 2024 · 3 comments
Assignees
Labels
bug Something isn't working Documentation

Comments

@scammo
Copy link

scammo commented Apr 2, 2024

I've been trying to run https://landrok.github.io/activitypub/fetch-peertube-outbox-activities.html but I can't get a result from the various Peertube accounts. For example: blender@video.blender.org.

Could you check if the documentation is still correct? Could you maybe look at some sample profiles that work with the script?

The first issues their about undefined properties, but event after defining them I still ran into issues.

Thanks again for all your work and documentation!

@landrok landrok self-assigned this Apr 2, 2024
@landrok landrok added bug Something isn't working Documentation labels Apr 2, 2024
@landrok
Copy link
Owner

landrok commented Apr 3, 2024

Hi @scammo
Peertube Ontology has been fixed. Can you update to 0.7.2 and test again with this example : https://landrok.github.io/activitypub/fetch-peertube-outbox-activities-using-ontologies.html ?

@scammo
Copy link
Author

scammo commented Apr 3, 2024

Hey, thanks for your quick result. I'm still getting errors when using the linked code and following two handles:
thunderbird_channel@tilvids.com, blender_channel@video.blender.org.
The problem seems to be that $item->object is of type string. A link to the resource, not an object.

ActivityPhp\Type\Extended\Activity\Announce {#320 ▼ // app/Http/Controllers/ExampleController.php:53
  -_props: array:6 [▼
    "type" => "Announce"
    "to" => array:1 [▶]
    "cc" => array:1 [▶]
    "id" => "https://tilvids.com/videos/watch/f895d15c-b97c-4c82-8661-c91e25dad078/announces/129600"
    "actor" => "https://tilvids.com/video-channels/thunderbird_channel"
    "object" => "https://tilvids.com/videos/watch/f895d15c-b97c-4c82-8661-c91e25dad078"
  ]
  #id: null
  #type: "Announce"
  #attachment: null
  #attributedTo: null
  #audience: null
  #content: null
  #context: null
  #contentMap: null
  #name: null
  #nameMap: null
  #endTime: null
  #generator: null
  #icon: null
  #image: null
  #inReplyTo: null
  #location: null
  #preview: null
  #published: null
  #replies: null
  #startTime: null
  #summary: null
  #summaryMap: null
  #tag: null
  #updated: null
  #url: null
  #to: null
  #bto: null
  #cc: null
  #bcc: null
  #mediaType: null
  #duration: null
  #source: null
  #actor: null
  #target: null
  #result: null
  #origin: null
  #instrument: null
  #object: null
}

@landrok
Copy link
Owner

landrok commented Apr 3, 2024

There are 2 different things:

thunderbird_channel@tilvids.com

You're true, Announce->object is a string (url)

blender_channel@video.blender.org

This one is more Nginx-y. Gateway randomly fails. So you need to catch exception.

Here is a naive example of how to do that :

use ActivityPhp\Server;
use Exception;

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

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

$handle = 'blender_channel@video.blender.org';
$handle = 'thunderbird_channel@tilvids.com';

// 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 = readNextPage($outbox, $page);
    $pages[] = $page;
}
echo "\n";

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

/**
 * This function retry to read the failing page FOREVER
 */
function readNextPage($outbox, $page)
{
    try {
        return $outbox->getPage($page->next);
    } catch(Exception $e) {
        sleep(5);
    }
    
    return readNextPage($outbox, $page);
}

Please take into consideration that this is just an example which should neither be used as is in a production environment nor in a controller, whether with Laravel or another framework 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Documentation
Projects
None yet
Development

No branches or pull requests

2 participants