-
-
Notifications
You must be signed in to change notification settings - Fork 2
Examples
Easily create and send a text-based post to BlueSky.
// Forge a new post with simple text
$post = bskyFacade($client)->post()->text("Hello, BlueSky!");
// Send the post to the server
$createdRecord = bskyFacade()->createRecord()
->record($post) // Include the forged post
->repo($client->authenticated()->did()) // Specify the authenticated user's DID
->collection($post->nsid()) // Use the appropriate collection namespace
->send();
// Output the URI of the created post
echo $createdRecord->uri();
Embed images into your posts for enhanced visual appeal.
use \Atproto\Lexicons\App\Bsky\Embed\Collections\ImageCollection;
use \Atproto\Lexicons\App\Bsky\Embed\Image;
// Upload an image to the server
$uploadedBlob = bskyFacade($client)->uploadBlob()
->blob('/path/to/image.jpg') // Specify the image path
->send()
->blob(); // Retrieve the uploaded blob metadata
// Forge a post embedding the uploaded image
$post = bskyFacade()->post()
->text("Hello, BlueSky with an image!")
->embed(bskyFacade()->imagesEmbed(
bskyFacade()->image($uploadedBlob, 'Image description')
));
// Send the post and log the URI
$createdRecord = bskyFacade()->createRecord()
->record($post)
->repo($client->authenticated()->did())
->collection($post->nsid())
->send();
echo $createdRecord->uri();
Add external links with thumbnails for informative posts.
// Upload an image for the link preview
$uploadedBlob = bskyFacade($client)->uploadBlob()
->blob('/path/to/image.jpg')
->send()
->blob();
// Forge external link details
$external = bskyFacade()->externalEmbed(
'https://example.com', // Link URL
'Example Website', // Link title
'A description of the website.' // Link description
)->thumb($uploadedBlob); // Add the uploaded image as a thumbnail
// Forge a post including the external link
$post = bskyFacade()->post()
->text("Check out this website!")
->embed($external);
// Send the post and retrieve the URI
$createdRecord = bskyFacade()->createRecord()
->record($post)
->repo($client->authenticated()->did())
->collection($post->nsid())
->send();
echo $createdRecord->uri();
Search for posts on BlueSky using keywords or filters.
// Perform a keyword search on posts
$response = bskyFacade()->searchPosts('keyword')
->send();
// Loop through and display the search results
foreach ($response->posts() as $post) {
echo $post->record()->text() . "\n";
}
Get a view of the requesting account's home timeline.
$feed = bskyFacade($client)->getTimeline()
->limit(10)
->send()
->feed();
foreach($feed as $entry) {
echo sprintf("Created by %s at %s" . PHP_EOL,
$entry->post()->author()->handle(),
$entry->post()->indexedAt()->format('d/m/Y H:i:s')
);
}
require_once("vendor/autoload.php");
use Atproto\Client;
use Atproto\DataModel\Blob\Blob;
use Atproto\Lexicons\App\Bsky\Embed\Video;
use Atproto\Responses\App\Bsky\Video\UploadVideoResponse;
use Atproto\Support\FileSupport;
$pdsEndpoint = $client->authenticated()->didDoc()->service()
->firstWhere('id', '#atproto_pds')['serviceEndpoint'];
$pdsHost = str_replace(
["https://", "http://"],
"did:web:",
$pdsEndpoint
);
// Generate a temporary token for uploading the video
$token = bskyFacade($client)->getServiceAuth()
->aud($pdsHost)
->lxm(bskyFacade()->uploadBlob()->nsid())
->exp(\Carbon\Carbon::now()->addMinutes(15)->timestamp)
->send()
->token();
$filePath = '/home/shahmal1yev/Videos/Screencasts/shortvideo.mp4';
$file = new FileSupport($filePath);
// Upload video
$uploadedVideo = bskyFacade()->uploadVideo(basename($filePath), $file, $token)->send();
// Check if the video upload returned a blob
if ($videoBlob = $uploadedVideo->has('blob')) {
$videoBlob = Blob::viaArray($uploadedVideo->blob());
}
// Wait for the job to complete if the video blob is not immediately available
while (! $videoBlob) {
$jobStatusResponse = bskyFacade()->getJobStatus($uploadedVideo->jobId()) // Use the job ID from the upload response
->send();
// Check if the job has completed successfully
if ($jobStatusResponse->jobStatus()->state() === 'JOB_STATE_COMPLETED') {
// Convert the video blob to an object
$videoBlob = Blob::viaArray($jobStatusResponse->jobStatus()->blob());
}
// Wait for 0.5 seconds before checking again
sleep(0.5);
}
// Create a post with the uploaded video embedded
$post = bskyFacade()->post()
->text("Hello, BlueSky! This is a video.")
->embed(new Video($videoBlob));
// Send the post to the server and log the created record's URI
$createdRecordRes = bskyFacade()->createRecord()
->repo($client->authenticated()->handle())
->collection($post->nsid())
->record($post)
->send();
// Output the URI of the created post
echo $createdRecordRes->uri();
Description | Link |
---|---|
Discord | You can join to Discord Server of the SDK |
Official Docs | AT Protocol Official Docs |
BlueSky Docs | BSky HTTP Reference Docs |
SDK Docs | SDK Official Docs |
Packagist | SDK available on Packagist |
Author | Created by @shahmal1yev with ❤️ |
Support | Support to my open source work on Github or Buymeacoffee |
Get started with BlueSky SDK today and integrate Bluesky into your projects! 🚀
-
🏠 Home
Introduction to the SDK and its features -
🚀 Quick Start
Get started quickly with the basics of using the Bluesky SDK -
⚙️ Installation
Step-by-step guide to installing the SDK -
🛠️ Architecture Overview
Learn about the SDK's structure and design principles -
📖 BskyFacade
Simplify API interactions with the facade -
💾 Serialization
Serialize and deserialize data effectively -
🔄 Session Management
Manage authentication and session reuse -
🧹 Casting
Explore type-safe response casting in the SDK -
💡 Examples
Practical usage examples for various features