cjrasmussen / BlueskyApi

Simple helper for interacting with the Bluesky API/AT protocol
MIT License
27 stars 5 forks source link

Can I specify one URL and use PHP to retrieve only one bluesky post by someone else? #7

Closed e1blue closed 10 months ago

e1blue commented 10 months ago

Can I specify one URL and use PHP to retrieve only one bluesky post by someone else?

cjrasmussen commented 10 months ago

Can you explain this a little bit further? Are you looking to get the most recent post by a user other than yourself, or a specific post by someone else, or something else entirely?

e1blue commented 10 months ago

I want to retrieve someone else's specific post. if I am using Bluesky and happen to find a post I like, can I use PHP to retrieve that one post? I want to embed it in my blog and display it.

cjrasmussen commented 10 months ago

This library won't give you a fancy embed image or anything like that - there are other libraries out there to do that - but you can get all of the metadata about a post from its URL doing something like this...


$bluesky = new BlueskyApi();
$bluesky->auth($handle, $password);

$url = 'https://bsky.app/profile/wearesopuzzled.com/post/3kjrgpm5iz22y';

$url_parts = explode('/', $url);
$post_handle = $url_parts[4];
$post_id = $url_parts[6];

$args = [
    'handle' => $post_handle,
];
$post_account = $bluesky->request('GET', 'com.atproto.identity.resolveHandle', $args);

$args = [
    'uri' => 'at://' . $post_account->did . '/app.bsky.feed.post/' . $post_id,
];
$response = $bluesky->request('GET', 'app.bsky.feed.getPostThread', $args);```

And then you can format it however you want.
e1blue commented 10 months ago

Thank you for your response. It worked as expected. It was very helpful.