Modified version of the simple class for making requests to the Bluesky API/AT protocol. Not affiliated with Bluesky.
This version saves the refresh token received from the API to a file so that it can reuse the session โ this is refreshed via com.atproto.server.refreshSession
rather than always creating a new session. This will help to avoid hitting rate limits on the com.atproto.server.createSession
endpoint depending on how you are using the library.
use cjrasmussen\BlueskyApi\BlueskyApi;
$bluesky = new BlueskyApi($handle, $app_password);
// SEND A MESSAGE
$args = [
'collection' => 'app.bsky.feed.post',
'repo' => $bluesky->getAccountDid(),
'record' => [
'text' => 'Testing #TestingInProduction',
'langs' => ['en'],
'createdAt' => date('c'),
'$type' => 'app.bsky.feed.post',
],
];
$data = $bluesky->request('POST', 'com.atproto.repo.createRecord', $args);
// SEND A MESSAGE WITH AN IMAGE, ASSUMING $file IS A PNG
$body = file_get_contents($file);
$response = $bluesky->request('POST', 'com.atproto.repo.uploadBlob', [], $body, 'image/png');
$image = $response->blob;
$args = [
'collection' => 'app.bsky.feed.post',
'repo' => $bluesky->getAccountDid(),
'record' => [
'text' => 'Testing with an image #TestingInProduction',
'langs' => ['en'],
'createdAt' => date('c'),
'$type' => 'app.bsky.feed.post',
'embed' => [
'$type' => 'app.bsky.embed.images',
'images' => [
[
'alt' => 'A test image',
'image' => $image,
],
],
],
],
];
$response = $bluesky->request('POST', 'com.atproto.repo.createRecord', $args);
Copy and include the file(s) any way you want.
See the original repo here.
BlueskyApi is MIT licensed.