ATPROTO協議的輕巧實施與Bluesky一起玩樂
在查看已經可用的庫以與Atproto通信的庫後,我決定走自己的路。我以某種方式不使用庫,其中包括其作曲家中的其他十幾個庫。 JSON,而真正的交流功能可以通過更少的第三方組件覆蓋。
目前(我稱其為α之前)我只包括一個第三方庫,即
也許將來會變得更多。
為了使一切變得更加混亂,我重命名了幾乎所有功能.....您可以找到我在此處實施的功能的列表:
由endpoint.md排序的實現功能
實現的函數按函數的名稱排序.md
您可以通過執行作曲家安裝圖書館
composer require schnoog/php_atproto
這將在通常的供應商目錄中安裝庫。現在,將file /vendor/schnoog/php_atproto/src/config.dist.php 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的內容並輸入您的憑據
如果您根本沒有安裝作曲家,這就是路要走。
我創建了第二個存儲庫,其中包括運行此內容所需的所有文件。
從這裡下載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);
是的,也很容易閱讀自己的時間軸(或feed或稱為feed)。 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);
我將創建一個列表,其中包含實現的功能和端點,並將嘗試使其保持最新狀態。
enasuned_sorted_by_endpoint.md
enasuned_sorted_by_funtions.md