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