PHP code example of shahmal1yev / blueskysdk

1. Go to this page and download the library: Download shahmal1yev/blueskysdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shahmal1yev / blueskysdk example snippets


use Atproto\Client;
use Atproto\Resources\Com\Atproto\Server\CreateSessionResource;

$client = new Client();

// Authenticate using your identifier (e.g., email) and password
$client->authenticate($identifier, $password);

// Once authenticated, you can retrieve the user's session resource
/** @var CreateSessionResource $session */
$session = $client->authenticated();

use Atproto\Contracts\ResourceContract;

// Example: Fetching a profile
$profile = $client->app()
                  ->bsky()
                  ->actor()
                  ->getProfile()
                  ->forge()
                  ->actor('some-actor-handle') // Specify the actor handle
                  ->send();

// Retrieve properties from the profile
/** @var string $displayName */
$displayName = $profile->displayName();

/** @var Carbon\Carbon $createdAt */
$createdAt = $profile->createdAt();

use Atproto\Resources\Assets\FollowersAsset;
use Atproto\Resources\Assets\FollowerAsset;

// Fetch the user's followers
/** @var FollowersAsset<FollowerAsset> $followers */
$followers = $profile->viewer()
                     ->knownFollowers()
                     ->followers();

foreach ($followers as $follower) {
    /** @var FollowerAsset $follower */
    echo $follower->displayName() . " - Created at: " . $follower->createdAt()->format(DATE_ATOM) . "\n";
}

use Atproto\Client;
use Atproto\API\App\Bsky\Actor\GetProfile;
use Atproto\Resources\App\Bsky\Actor\GetProfileResource;

$client->authenticate('[email protected]', 'password');

$client->app()
       ->bsky()
       ->actor()
       ->getProfile()
       ->forge();
       // ->actor($client->authenticated()->did());

/** @var GetProfileResource $user */
$user = $client->send();

// Output profile details
echo "Display Name: " . $user->displayName() . "\n";
echo "Created At: " . $user->createdAt()->toDateTimeString() . "\n";

// Accessing and iterating over followers
$followers = $user->viewer()->knownFollowers()->followers();

foreach ($followers as $follower) {
    echo $follower->displayName() . " followed on " . $follower->createdAt()->format(DATE_ATOM) . "\n";
}