Bluesky와 함께 재미있는 Atproto 프로토콜의 경량 구현
Atproto와 의사 소통하기 위해 이미 사용 가능한 도서관을 살펴본 후 나는 내 자신의 길을 가기로 결정했습니다. Composer.json에 12 개의 다른 라이브러리가 포함 된 라이브러리를 사용하는 것을 거부하는 반면 실제 커뮤니케이션 기능은 적은 타사 구성 요소로 다룰 수 있습니다.
현재 (나는 그것을 사전 알파라고 부를 것입니다) 나는 하나의 제 3 자 도서관, 즉 단 하나만 포함합니다.
어쩌면 그것은 미래에 더 많은 것이 될 것입니다.
엉망이 덜 만들기 위해 거의 모든 기능으로 이름을 바꿨습니다 ..... 여기에서 구현 한 기능 목록을 찾을 수 있습니다.
구현 된 함수는 endpoint.md로 정렬됩니다
구현 된 함수는 function.md의 이름으로 정렬됩니다
실행을 통해 작곡가로 라이브러리를 설치할 수 있습니다
composer require schnoog/php_atproto
이것은 일반적인 공급 업체 디렉토리에 라이브러리를 설치합니다. 이제 파일 /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 의 내용을 변경하고 자격 증명을 입력하십시오.
작곡가를 전혀 설치하지 않았다면 이것이가는 길입니다.
이 작업을 실행하는 데 필요한 모든 파일을 포함하는 두 번째 저장소를 만들었습니다.
여기에서 zipped 버전을 다운로드하십시오 : PACPED PHP_ATPROTO 버전
압축을 풀고 config.php 에서 자격 증명을 설정하면 갈 준비가되었습니다. 예, 정말 쉽습니다
이것은 당신이 전체 저장소 사본을
또는
원하는 디렉토리에 파일이있는 후 파일 config.dist.php 설치 디렉토리에 복사하여 config.php 로 이름을 바꿉니다.
composer install 실행하여 종속성을 설치하는 것을 잊지 마십시오.
config.php 의 내용을 변경하고 자격 증명을 입력하십시오.
나는 (현재) 몇 가지만있다.
나는 OOP의 가장 큰 팬이 아닙니다. 내 디지털 세상의 모든 것이 수업 일 필요는 없습니다. 그래서 인터페이스를 순전히 계속 유지하겠습니다 (특히 게시물을 만드는 것이 수업에서 캡슐화하기가 더 쉬울 것입니다).
알겠습니다. 사용 가능한 것을 확인해 봅시다
이 작은 예는 서버에 대해 인증되고 토큰을 로컬로 저장합니다. 로컬 저장 토큰을 사용할 수 있고 마지막 유효성 검사가 $config['atproto']['storedsession_validity'] 에 지정된 것보다 더 많이 수행되면 초기에 유효성은 백엔드 (내 케이스 Bluesky)에 대해 확인됩니다.
그리고 여기에 나 자신을 상기시켜줍니다. paste if (!atp_session_get())return false; 인터페이스의 시작 부분에서 (게시물, 타임 라인 get) 함수.
<?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