Small example how to post something to Bluesky using PHP.
This example is based on the library cjrasmussen/bluesky-api.
composer require cjrasmussen/bluesky-api
This is the result of the snippet below:
Small example how to post something to Bluesky using PHP.
This example is based on the library cjrasmussen/bluesky-api.
composer require cjrasmussen/bluesky-api
This is the result of the snippet below:
| <?php | |
| require 'vendor/autoload.php'; | |
| use cjrasmussen\BlueskyApi\BlueskyApi; | |
| // full handle without the @-sign: | |
| $handle = 'yourhandle.bsky.social'; | |
| // retrieve app password here: https://bsky.app/settings/app-passwords | |
| $app_password = 'xxxx-xxxx-xxxx-xxxx'; | |
| $bluesky = new BlueskyApi($handle, $app_password); | |
| // Post a message | |
| $args = [ | |
| 'collection' => 'app.bsky.feed.post', | |
| 'repo' => $bluesky->getAccountDid(), | |
| 'record' => [ | |
| // The actual text of the post | |
| 'text' => 'This is a test message! With a link!', | |
| // The facets below are optional, but you need them to create a link in your message | |
| 'facets' => [ | |
| [ | |
| "index" => [ | |
| "byteStart" => 30, // where the link should start. Character 30 here is from 'a link' | |
| "byteEnd" => 36, // and where the link should end - just before the exclamation mark. | |
| ], | |
| "features" => [ | |
| [ | |
| '$type' => "app.bsky.richtext.facet#link", | |
| 'uri' => 'https://geert.ninja/', // URL to link to | |
| ], | |
| ], | |
| ], | |
| ], | |
| 'langs' => ['en'], // language (English here) | |
| 'createdAt' => date('c'), // just the current timestamp | |
| '$type' => 'app.bsky.feed.post', | |
| ], | |
| ]; | |
| // Actually post it to Bluesky | |
| $data = $bluesky->request('POST', 'com.atproto.repo.createRecord', $args); |