PHP code example of mov / php-bluesky

1. Go to this page and download the library: Download mov/php-bluesky 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/ */

    

mov / php-bluesky example snippets


// Simple text post
$blueskyClient = new BlueskyClient();
$blueskyClient->authenticate('<YOUR BLUESKY HANDLE>', '<YOUR APP PASSWORD>');
$blueskyClient->post('Post something.');

// Upload image and post it
$blueskyClient = new BlueskyClient();
$blueskyClient->authenticate('<YOUR BLUESKY HANDLE>', '<YOUR APP PASSWORD>');
$image = file_get_contents('<PATH/TO/IMAGE>');
$contentType = mime_content_type('<PATH/TO/IMAGE>');
$responseJson = $blueskyClient->uploadBlob($image, $contentType);
$response = json_decode($responseJson, true);
$embed = [
    '$type' => 'app.bsky.embed.images',
    'images' => [
        [
            'alt' => 'A test image',
            'image' => $response['blob'],
        ],
    ]
];
$blueskyClient->post('Additional text', $embed);