beeyev/gettr-api-client-php

此软件包已废弃,不再维护。未建议替代软件包。

GETTR.com API PHP 客户端

1.0.2 2021-07-16 14:41 UTC

This package is auto-updated.

Last update: 2023-06-16 19:21:53 UTC


README

Latest Stable Version Total Downloads License

这是一个使用 PHP 编写并支持 Laravel 的 GETTR.com 客户端库。

此库使用网站的非官方公开可访问 API 端点,请注意某些端点可能会随时停止工作。无论如何,如果出现问题或缺失功能,请提交问题。

安装

通过 composer 安装软件包

$ composer require beeyev/gettr-api-client-php

可选,如果您使用 Laravel,可以使用以下命令发布此软件包的配置文件

$ php artisan vendor:publish --provider="Beeyev\GettrApiClient\Adapters\Laravel\GettrServiceProvider" --tag=config

以下配置文件将发布到 config/gettr.php,如果您想使用需要授权的方法,请设置 usertoken。继续阅读以了解如何获取授权令牌。

return [  
  'user'  => '',  
  'token' => '',  
];

如何获取与 Gettr 通信的凭证

  1. gettr.com 上进行认证
  2. 在浏览器中打开开发者工具,并在任何调用 api.gettr.com 端点的 HTTP 请求头中的 x-app-auth 中找到 usernametoken 值。
显示截图

如何使用

示例

use Beeyev\GettrApiClient\Gettr;

$user = 'username';  
$token = 'token';  
$gettr = new Gettr($user, $token); //Initial values are optional  
$postData = $gettr->post()->get('p4e8x3'); // Read on to explore all available methods

或者您可以直接使用 Laravel 门面

$postData = \Gettr::post()->get('p4e8x3'); //Will return an array of raw json
$userPostsData = \Gettr::post()->getUserPosts('enzo20');

使用 Laravel 门面的 API 方法

帖子

//Get a post
Gettr::post()->get(string $postId);

//Deletes user's post
Gettr::post()->delete(string $postId);

//Make a repost
Gettr::post()->repost(string $postId);

//Undo a repost
Gettr::post()->undoRepost(string $postId);

//Get a user's posts
Gettr::post()->getUserPosts(string $username, int $offset = 0, int $maximum = 20, string $direction = 'rev');

//Get a user's replies
Gettr::post()->getUserReplies(string $username, int $offset = 0, int $maximum = 20, string $direction = 'rev');

//Returns a user's media
Gettr::post()->getUserMedia(string $username, int $offset = 0, int $maximum = 20, string $direction = 'rev');

//Returns a list of posts which were liked by a user
Gettr::post()->getPostsLikedByUser(string $username, int $offset = 0, int $maximum = 20, string $direction = 'rev');

//Returns a list of users who liked a post
Gettr::post()->getUsersLikedPost(string $postId, int $offset = 0, int $maximum = 20, string $direction = 'rev');

//Returns a list of users who reposted a post
Gettr::post()->getUsersRepostedPost(string $postId, int $offset = 0, int $maximum = 20, string $direction = 'rev');

//Returns a post's comments.
Gettr::post()->comments(string $postId, int $offset = 0, int $maximum = 20, string $direction = 'rev');

//Searches posts with a phrase
Gettr::post()->search(string $query, int $offset = 0, int $maximum = 20);

//Pins a specified post
//This will pin a post at the top of your profile and replace any previously pinned
Gettr::post()->pin(string $postId);

//Create a new post
//Unfortunately I did not have enough time to figure it out how this API method should work.
//Quote post and Reply methods work the same, so this is why I did not even try to implement them.
//I will appreciate if smb would help me with this.
//Gettr::post()->create(string $text);

点赞

//Like a post
//The result will also contain total number of likes but only when you make a change
Gettr::like()->likePost(string $postId);

//Unlike a post
Gettr::like()->unlikePost(string $postId);

//Like a comment.
Gettr::like()->likeComment(string $commentId);

//Unlike a comment
Gettr::like()->unlikeComment(string $commentId);

//Get all posts liked by a user
Gettr::like()->getPostsLikedByUser(string $username);

用户

//Get User information
Gettr::user()->info(string $username);

//Follow a user
Gettr::user()->follow(string $username);

//Unfollow a user
Gettr::user()->unfollow(string $username);

//Mute a user
Gettr::user()->mute(string $username);

//Unmute a user
Gettr::user()->unmute(string $username);

//Returns list of muted users. ! Require authorisation
Gettr::user()->getMutes(int $offset = 0, int $maximum = 20);

//Block a user. ! Require authorisation
Gettr::user()->block(string $username);

//Unblock a user. ! Require authorisation
Gettr::user()->unblock(string $username);

//Returns list of blocked users. ! Require authorisation
Gettr::user()->getBlocked(int $offset = 0, int $maximum = 20);

//Searches users
Gettr::user()->search(string $query,  int $offset = 0, int $maximum = 20);

//Check if Username exists
Gettr::user()->checkIfUsernameExists(string $username);

//Returns list of user follows.
Gettr::user()->followings(string $username, int $offset = 0, int $maximum = 20);

//Returns a list of user followers.
Gettr::user()->followers(string $username, int $offset = 0, int $maximum = 20);

//Returns current user's timeline, (same thing what you see on the home page)
Gettr::user()->timeline(int $offset = 0, int $maximum = 20, string $direction = 'rev');

建议

//Returns a list of suggested users.
Gettr::suggested()->users(int $offset = 0, int $maximum = 20);

//Returns a list of suggested hashtags.
Gettr::suggested()->hashtags(int $offset = 0, int $maximum = 20);

测试

¯_(ツ)_/¯

许可证

MIT 许可证(MIT)。请参阅 许可证文件 了解更多信息。