Skip to content

eiland-asbl/php2Bluesky

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation


php2Bluesky

A simple library that allows posting to Bluesky via the API.

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

With all the uncertainty surrounding the future of X (née Twitter), I decided to take a look at Bluesky which somewhat ironically has its roots in Twitter where it was started as an internal project. Bluesky is still in beta and is invite-only. I worry about Bluesky's long-term given that ultimately it too has to make money, something that Twitter has singularly failed to do. None of this, of course, affects the topic today which is posting to Bluesky via the API.

Buy Me a Coffee at ko-fi.com

(back to top)

Built With

(back to top)

Getting Started

Running the script is very straightforward:

  1. download the code/clone the repository
  2. install composer
  3. add the BlueskyAPI

composer.phar require cjrasmussen/bluesky-api

Now you can inspect and update index.php to get some examples.

If you are interested in what is happening under the hood then read this series of blog posts.

Prerequisites

Requirements are very simple, it requires the following:

  1. PHP (I tested on v8.1.13) - requires php-dom and php-gd
  2. Clark Rasmussen's BlueskyApi (requires v2 or above)
  3. a Bluesky account and an Application Password (see this blog post for details of how to do that).

Installation

  1. Clone the repo:
    git clone https://github.com/williamsdb/php2Bluesky.git

(back to top)

Usage

Here's a few examples to get you started.

  • Setup and connect to Bluesky:
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/functions.php';

$handle = 'yourhandle.bsky.social';
$password = 'abcd-efgh-ijkl-mnop';
    
// connect to Bluesky API
$connection = bluesky_connect($handle, $password);
  • Sending text with tags
$text = "This is some text with a #hashtag.";

$response = post_to_bluesky($connection, $text);
print_r($response);
  • Uploading a post with a single image and embedded url
$filename1 = 'https://upload.wikimedia.org/wikipedia/en/6/67/Bluesky_User_Profile.png';
$text = 'Screenshot of Bluesky';
$alt = 'This is the screenshot that Wikipedia uses for their https://en.wikipedia.org/wiki/Bluesky entry.';

$image = upload_media_to_bluesky($connection, $filename1);

$response = post_to_bluesky($connection, $text, $image, '', $alt);
print_r($response);
  • Uploading a post with multiple images (both local and remote)
$filename1 = 'https://upload.wikimedia.org/wikipedia/en/6/67/Bluesky_User_Profile.png';
$filename2 = '/Users/neilthompson/Development/php2Bluesky/Screenshot1.png';
$filename3 = 'https://www.spokenlikeageek.com/wp-content/uploads/2024/11/2024-11-18-19-28-59.png';
$filename4 = '/Users/neilthompson/Development/php2Bluesky/Screenshot2.png';
$text = 'An example of four images taken both from a local machine and remote locations with some alt tags';
    
// send multiple images with text
$image1 = upload_media_to_bluesky($connection, $filename1);
$image2 = upload_media_to_bluesky($connection, $filename2);
$image3 = upload_media_to_bluesky($connection, $filename3);
$image4 = upload_media_to_bluesky($connection, $filename4);
$imageArray = array($image1, $image2, $image3, $image4); 
$alt = array('this has an alt', 'so does this');
    
$response = post_to_bluesky($connection, $text, $imageArray, '', $alt);
print_r($response);

(back to top)

Known Issues

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Thanks to the follow who have provided techincal and/or financial support for the project:

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the GNU General Public License v3.0. See LICENSE for more information.

(back to top)

Contact

Bluesky - @spokenlikeageek.com

Mastodon - @spokenlikeageek

X - @spokenlikeageek

Website - https://spokenlikeageek.com

Project link - Github

(back to top)

Acknowledgments

(back to top)

About

Helper library to post to Bluesky Social

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%