定制 revolution/laravel-bluesky 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

revolution/laravel-bluesky

最新稳定版本:1.1.6

Composer 安装命令:

composer require revolution/laravel-bluesky

包简介

Bluesky(AT Protocol) for Laravel

README 文档

README

test packagist Maintainability Code Coverage

Ask DeepWiki

Requirements

  • PHP >= 8.2
  • Laravel >= 11.x

Version

ver PHP Laravel
1.x ^8.2 ^11.x
  • The auto-generated code from lexicon may contain breaking changes.

Installation

composer require revolution/laravel-bluesky

Basically, everything can be set in the .env file, so publishing the config file is optional.

Uninstall

composer remove revolution/laravel-bluesky

Quick start

Search posts (no auth required, no need for your own account)

There are many public APIs that do not require authentication if you just want to retrieve data.

Note Due to temporary API restrictions, searchPosts() currently requires authentication. Please use the authenticated example below instead.

// routes/web.php (CURRENTLY NOT WORKING - unauthenticated usage is temporarily restricted)

use Illuminate\Support\Facades\Route;
use Revolution\Bluesky\Facades\Bluesky;

Route::get('search', function () {
    /** @var \Illuminate\Http\Client\Response $response */
    $response = Bluesky::searchPosts(q: '#bluesky', limit: 10);

    $response->collect('posts')
        ->each(function (array $post) {
            dump(data_get($post, 'author.displayName'));
            dump(data_get($post, 'author.handle'));
            dump(data_get($post, 'author.did'));
            dump(data_get($post, 'record.text'));
        });
});

Authenticated usage (currently required due to temporary API restriction)

// routes/web.php

use Illuminate\Support\Facades\Route;
use Revolution\Bluesky\Facades\Bluesky;

Route::get('search-auth', function () {
    $response = Bluesky::login(identifier: config('bluesky.identifier'), password: config('bluesky.password'))
        ->searchPosts(q: '#bluesky', limit: 10);

    $response->collect('posts')
        ->each(function (array $post) {
            dump(data_get($post, 'author.displayName'));
            dump(data_get($post, 'author.handle'));
            dump(data_get($post, 'author.did'));
            dump(data_get($post, 'record.text'));
        });
});

Get someone's posts (no auth required)

// routes/web.php

use Illuminate\Support\Facades\Route;
use Revolution\Bluesky\Facades\Bluesky;

Route::get('feed', function () {
    // "actor" is did(did:plc:***) or handle(***.bsky.social, alice.test)
    $response = Bluesky::getAuthorFeed(actor: '***.bsky.social');

    $response->collect('feed')
        ->each(function (array $feed) {
            dump(data_get($feed, 'post.author.displayName'));
            dump(data_get($feed, 'post.record.text'));
        });
});

You can get your own posts by specifying your did or handle as the actor. No authentication is required to get and save your own posts.

Create a post (requires auth)

There are two authentication methods for Bluesky: "App password" and "OAuth". Here we will use "App password". Obtain the App password from Bluesky and set it in .env.

// .env

BLUESKY_IDENTIFIER=***.bsky.social
BLUESKY_APP_PASSWORD=****-****-****-****
// routes/web.php

use Illuminate\Support\Facades\Route;
use Revolution\Bluesky\Facades\Bluesky;

Route::get('post', function () {
    $response = Bluesky::login(identifier: config('bluesky.identifier'), password: config('bluesky.password'))
                       ->post('Hello Bluesky');
});

This is easy if you're just sending simple text, but in the real world you'll need to use TextBuilder to make links and tags work.

// routes/web.php

use Illuminate\Support\Facades\Route;
use Revolution\Bluesky\Facades\Bluesky;
use Revolution\Bluesky\Record\Post;
use Revolution\Bluesky\RichText\TextBuilder;

Route::get('text-builder', function () {
    $post = Post::build(function (TextBuilder $builder) {
        $builder->text('Hello Bluesky')
                ->newLine(count: 2)
                ->link('https://bsky.app/')
                ->newLine()
                ->tag('#Bluesky');
    });

    $response = Bluesky::login(identifier: config('bluesky.identifier'), password: config('bluesky.password'))
                       ->post($post);
});

Following message will be posted:

Hello Bluesky

https://bsky.app/
#Bluesky

To authenticate with OAuth, read the Socialite documentation.

Usage

Advanced

Sample project

Contracts

https://github.com/invokable/atproto-lexicon-contracts

LICENCE

MIT

统计信息

  • 总下载量: 13.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 41
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 41
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-19