Download the PHP package williamsdb/php2bluesky without Composer

On this page you can find all versions of the php package williamsdb/php2bluesky. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php2bluesky


php2Bluesky

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

Table of Contents
  1. About The Project
    • Built With
  2. Getting Started
    • Prerequisites
    • Installation
  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. 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.

I needed a way to post to Bluesky from PHP and so I searched for a library to help and when I couldn't find one I wrote this.

Buy Me a Coffee at ko-fi.com

(back to top)

Built With

(back to top)

Getting Started

NOTE: This is for v2 of php2Bluesky. If you are looking for the v1 details you can find that here.

Running the script is very straightforward:

  1. install composer
  2. add the BlueskyAPI

composer.phar require cjrasmussen/bluesky-api

  1. add php2Bluesky

composer.phar require williamsdb/php2bluesky

Now you can inspect example.php to get some examples and/or see below.

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)
  4. ffprobe if you intend to upload videos or gifs (optional)
  5. ffmpeg if you intend to upload videos or gifs (optional).

Read more about the requirements for video upload here.

Installation

  1. As above

(back to top)

Usage

Here's a few examples to get you started.

Note: connection to the Bluesky API is made via Clark Rasmussen's BlueskyApi which this makes a connection to Bluesky and manages tokens etc. See here for more details.

Setup and connect to Bluesky

Overriding the defaults

When you instantiate php2Bluesky a number of defaults are set as shown in the table below. However, you can override these as follows:

See details below on how to set these.

Name Default values Explanation
$linkCardFallback 'BLANK' What should happen if a linkcard doesn't have any associated image.

Possibe values:

RANDOM - a random image taken from $randomImageURL
BLANK - a blank image
ERROR - throw an error
URL - the image at this location, URL=https://...
$failOverMaxPostSize FALSE Throw an error if the text is longer than the allowed length of a post.
$randomImageURL 'https://picsum.photos/1024/536' Where to source the random image. Use with $linkCardFallback above.
$fileUploadDir '/tmp' Where to upload images to before posting them. Make sure that the process has permissions to write here.
$defaultLang ['en'] The default languages of posts. This must be specified as an array.
$autoRotate true A boolean indicating whether images should be auto rotated based on their EXIF data.

Sending text with tags

Uploading a post with a single image and embedded url

Uploading a post with multiple images (both local and remote)

Uploading a post with a single video

Adding labels

Bluesky allows certain lables to be applied to posts to indicate whether they include any graphic content. There is a table below of what labels are supported but also see BlueskyConsts.php for the latest.

Label Value UI Label Explanation
porn Adult Explicit/erotic sexual content
sexual Suggestive Mild or suggestive sexual themes
nudity Nudity Non‑erotic or artistic nudity
graphic-media Graphic Media Violent or graphic content
!no-unauthenticated n/a makes the content inaccessible to logged-out users in applications which respect the label.

Setting the language

By default the language of your posts is set to English but you can override this in one of two ways. Either specify the langauge when creating the instance of php2Bluesky (see above) or pass it when posting. It must be an array even if you are passing a single language.

It is also possible to pass multiple languages as follows:

Getting current rate limits

Once you have a connection created, you can find out what your rate limit is, how many messages you can send, and when the rate limit resets. Use this to ensure that your messages don't get rejected.

The above returns an array as follows:

Setting who can reply to a post

v2.3.11 and above

With this call, you are able to set who is able to reply to a post. Unlike the other calls, you can ONLY do this after posting.

You can send up to five allow values as an array, i.e ['mention', 'follower']

Allow Value Explanation
mention Anyone mentioned in the post
following Anyone you are following
follower Anyone who is a follower
list Anyone in this list...
NOT CURRENTLY SUPPORTED
[] Empty array - nobody can reply

Error Codes

List of error codes and messages that are thrown by php2Bluesky.

Message Code
BLANK specified for fallback image but blank.png is missing. 1001
Could not determine mime type of file. 1002
File type not supported: <mime type> 1003
Could not get the size of the image. 1004
Provided text greater than <BlueskyConsts::MAX_POST_SIZE> 1005
Error loading url: <url> 1006
No suitable image found for link card. 1007
Video duration exceeds maximum allowed duration of <BlueskyConsts::MAX_VIDEO_DURATION> seconds. 1009
Failed to fetch remote file: <error> - <url> 1010
No post id found. 1011
UNUSED 1012
Local file does not exist: <filename> 1013
Could not create image resource for resizing 1014
Unsupported label: <label> 1015
FFprobe failed (code <error code>): <output> 1016
Failed to parse ffprobe JSON: <output> 1017
Unable to determine video duration. 1018
FFmpeg not found in the local directory or globally. 1019
FFmpeg failed (code <error code>): <output> 1020
Output file missing or empty. FFmpeg output: <output> 1021
FFprobe not found in the local directory or globally. 1022
Unsupported Threadgate: <allow> 1023

(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)


All versions of php2bluesky with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
cjrasmussen/bluesky-api Version ^2.0
ext-dom Version *
ext-gd Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package williamsdb/php2bluesky contains the following files

Loading the files please wait ...