Blueskyを楽しむためのAtprotoプロトコルの軽量の実装
Atprotoと通信するためにすでに利用可能なライブラリを調べた後、私は自分の道を行くことにしました。 Composer.jsonに他の数十のライブラリを含むライブラリを使用することをどうにか控えますが、実際の通信機能は、より少ないサードパーティコンポーネントでカバーできます。
現在(私はそれを事前アルファと呼びます)、私は1つのサードパーティライブラリのみを含めます。
たぶんそれは将来より多くなるでしょう。
それをすべて混乱させるために、私はほとんどすべての関数を変更しました.....ここで実装した関数のリストを見つけることができます:
endpoint.mdによってソートされた実装関数
function.mdの名前でソートされた実装された関数
実行して、作曲家とライブラリをインストールできます
composer require schnoog/php_atproto
これにより、ライブラリが通常のベンダーディレクトリにインストールされます。 file /vendor/schnoog/php_atproto/src/config.dist.phpをインストールディレクトリにコピーし、 config.phpに名前を変更します
または、インストールディレクトリ内から次のコマンドを使用してファイルを自動的にコピーします(インストールディレクトリにファイル名config.phpがある場合、上書きされません。
php -r 'if(!file_exists(__DIR__ . "/config.php")) copy (__DIR__ . "/vendor/schnoog/php_atproto/src/config.dist.php", __DIR__ . "/config.php");'
config.phpのコンテンツを変更し、資格情報を入力します
これは、作曲家をまったくインストールしていない場合に行く方法です。
このことを実行するために必要なすべてのファイルを含む2番目のリポジトリを作成しました。
zippedバージョンをこちらからダウンロードしてください:詰め込まれたphp_atprotoバージョン
それを解凍するだけで、 config.phpに資格情報を設定すると、準備ができています。はい、本当に簡単です
これは、あなたがどちらかによってリポジトリ全体のコピーを持っていることを意味します
または
目的のディレクトリにファイルがある後、ファイルconfig.dist.phpをインストールディレクトリにコピーし、 config.phpに名前を変更します
composer installを実行して依存関係をインストールすることを忘れないでください
config.phpのコンテンツを変更し、資格情報を入力します
私は(現在)少数しか持っていません:
私はOOPの最大のファンではありません。私のデジタルの世界のすべてがクラスでなければならないわけではありません。したがって、インターフェイスを純粋に機能させます(特に投稿を作成するのがクラスでカプセル化する方が簡単なEvenso)
わかりました、利用可能なものを確認しましょう
この小さな例は、サーバーに対して認証され、トークンをローカルに保存するだけです。ローカル保存トークンが利用可能であり、最後の妥当性チェックが$config['atproto']['storedsession_validity']で指定されたよりも多く実行された場合、有効性はバックエンドに対してチェックされます(私の場合、BlueSkyで)
そして、ここで自分自身に思い出させます:貼り付けif (!atp_session_get())return false;インターフェイスの先頭(投稿、タイムラインを取得...)関数。
<?php
require_once(__DIR__ . "/src/includer.php");
if (!atp_session_get()){
echo "UNABLE TO ESTABLISH SESSION" . PHP_EOL;
print_r($config['error']);
}else{
echo "Session estalished and checked" . PHP_EOL;
}
はい、このことは実際に独自のタイムラインに投稿できます。 (includer.phpを含める後)する必要があるのは、関数を呼び出すことだけです。
しかし、これには(地球上のすべてのように)制限があります:
メイン関数ATP_CREATE_POSTのパラメーターについて少し紹介します
$text = "This is the text to post, n containing mentioning @develobot.bsky.social and a link https://github.com/schnoog/php_atproto";
$lang = ['de','en'];
$add_link_facets = true;
$add_mentions_facets = true;
$images = [ __DIR__ . "/pic01.jpg" , __DIR__ . "/pic02.jpg"];
$images_alts = [ '', 'Alt text for second image'];
前述のように、画像またはウェブカードのいずれかを持つことができます。両方を定義した場合(およびそれらで機能を提供する;))、ウェブカードのみが表示されます
$website_uri = "https://github.com/schnoog/php_atproto";
$website_title = "My user defined title";
$website_description = "My user defined description";
$website_image = __DIR__ . "/website_image.png";
わかりました、あなたがどのように電話されるかを見てみましょう
<?php
require_once(__DIR__ . "/src/includer.php");
/*
Let's define some variables
*/
$text = "This is the text to post, n containing mentioning @develobot.bsky.social and a link https://github.com/schnoog/php_atproto";
$lang = ['de','en'];
$add_link_facets = true;
$add_mentions_facets = true;
$images = [ __DIR__ . "/pic01.jpg" , __DIR__ . "/pic02.jpg"];
$images_alts = [ '', 'Alt text for second image'];
$website_uri = "https://github.com/schnoog/php_atproto";
$website_title = "My user defined title";
$website_description = "My user defined description";
$website_image = __DIR__ . "/website_image.png";
//The most simple text post - parsing of mentions and links is ENABLED by default
$answer = atp_create_post($text);
//Now a post, just like above, but this time with the 2 defined images attached, and the $lang keys
$answer = atp_create_post($text,$lang,true,true,$images,$images_alts);
//And now a post which includes a webcard, for which we only provide the URL
$answer = atp_create_post($text,$lang,true,true,[],[],$website_uri);
//Why not a post with a full user defined webcard? Own title, description and image
$answer = atp_create_post($text,null,true,true,[],[],$website_uri,$website_title,$website_description,$website_image);
はい、また、独自のタイムライン(またはフィード、またはそれが呼ばれている)を読むことも非常に簡単です。 TBH、最も簡単なものです
<?php
require_once(__DIR__ . "/src/includer.php");
//Get 27 entries of the own timeline and print it by DebugOut
$timeline = atp_get_own_timeline(27);
DebugOut($timeline);
この機能は何らかの形で限られています。現在、 app.bsky.feed.searchPostsから有効な結果を受け取ることができません。代わりに、 https://search.bsky.social/search/postsから読んでいます
良くありませんが、うまくいきます
<?php
require_once(__DIR__ . "/src/includer.php");
//Search for posts containing "Arduino" and print the result
$answer = atp_search_posts_by_term("Arduino");
DebugOut($answer);
機能とエンドポイントが実装されたリストを作成し、最新の状態に保ちます。
実装_sorted_by_endpoint.md
実装_sorted_by_funtions.md