potibm / phluesky
一个用于通过AT协议向Bluesky社交网络发送消息的PHP库。
v0.4.0
2024-05-24 18:05 UTC
Requires
- php: ^8.2
- ext-fileinfo: *
- php-http/discovery: ^1.19
- psr/http-client: ^1.0
- psr/http-client-implementation: *
- psr/http-factory: ^1.0
- psr/http-factory-implementation: *
- psr/http-message: ^2.0
- psr/http-message-implementation: *
Requires (Dev)
- nyholm/psr7: ^1.8
- phpunit/phpunit: ^10
- psalm/plugin-phpunit: ^0.18.4
- symfony/http-client: ^6.3
- symplify/easy-coding-standard: ^12.0.8
- vimeo/psalm: ^5.15
README
一个用于Bluesky社交的,使用AT协议的小型PHP库。
使用方法
安装
建议使用composer进行安装
composer require potibm/phluesky
您需要一个来自此列表的PSR-7、PSR-17和PSR-18客户端或适配器。对于开发,使用了symfony/http-client和nyholm/psr7。
HTTP服务发现将执行魔法。在大多数情况下不需要额外的步骤。
设置和发布简单消息
$api = new BlueskyApi('nick.bsky.social', 'abcd-efgh-ijkl-mnop');
$postService = new \potibm\Bluesky\BlueskyPostService($api);
$post = \potibm\Bluesky\Feed\Post::create('✨ example mentioning @atproto.com to share the URL 👨❤️👨 https://en.wikipedia.org/wiki/CBOR.');
$response = $api->createRecord($post);
在帖子文本中添加提及和链接
$post = \potibm\Bluesky\Feed\Post::create('✨ example mentioning @atproto.com to share the URL 👨❤️👨 https://en.wikipedia.org/wiki/CBOR.');
$post = $postService->addFacetsFromMentionsAndLinks($post);
在帖子文本中添加提及、链接和标签
$post = \potibm\Bluesky\Feed\Post::create('✨ example mentioning @atproto.com to share the URL 👨❤️👨 https://en.wikipedia.org/wiki/CBOR. and #HashtagFun');
$post = $postService->addFacetsFromMentionsAndLinksAndTags($post);
添加图片
https://atproto.com/blog/create-post#images-embeds
$post = \potibm\Bluesky\Feed\Post::create('example post with image attached');
$post = $postService->addImage(
$post,
'image.jpg',
'alt text'
);
添加网站卡片嵌入
https://atproto.com/blog/create-post#website-card-embeds
$post = \potibm\Bluesky\Feed\Post::create('post which embeds an external URL as a card');
$post = $postService->addWebsiteCard(
$post,
'https://example.com',
'Example website',
'Example website description',
'optionalimage.jpg'
);
回复帖子
https://atproto.com/blog/create-post#replies
$post = \potibm\Bluesky\Feed\Post::create('example of a reply');
$post = $postService->addReply(
$post,
'at://did:plc:u5cwb2mwiv2bfq53cjufe6yn/app.bsky.feed.post/3k43tv4rft22g'
);
引用帖子
https://atproto.com/blog/create-post#quote-posts
$post = \potibm\Bluesky\Feed\Post::create('example of a quote-post');
$post = $postService->addQuote(
$post,
'at://did:plc:u5cwb2mwiv2bfq53cjufe6yn/app.bsky.feed.post/3k44deefqdk2g'
);
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。