fundevogel/php-mastodon
最新稳定版本:0.6.0
Composer 安装命令:
composer require fundevogel/php-mastodon
包简介
A small PHP library for interacting with Mastodon's REST API.
关键字:
README 文档
README
A small PHP library for interacting with Mastodon's REST API. Its documentation can be found here.
Note: Before you get started, be sure to create an application (under "Development" in your profile settings) first.
Getting started
Install this package with Composer:
composer require fundevogel/php-mastodon
To get an idea how you could implement this, have a look at these examples:
<?php require_once('vendor/autoload.php'); use Fundevogel\Mastodon\Api; # Initialize Api for given instance (defaults to 'mastodon.social') $api = new Api('freiburg.social'); # Generate access token via .. # (1) .. OAuth call or .. $api->accessToken = $api->oauth()->token('cl13nt_1d', 'cl13nt_s3cr3t')['access_token']; # (2) .. app creation (create an app, get one `access_token` for free!) $api->accessToken = 'ur-t0t4lly-s3cr3t-p4ssw@rd'; # If you want to obtain an authorization code, and want to know where to get one .. $url = $api->getAuthURL('cl13nt_1d'); # .. but you might want to provide what you have & use the login helper $api->logIn(); # This helper takes the authorization code as parameter - however, # if you provided client key / secret / access token, # it will attempt to provide whatever access level is possible # Fetch statuses of given account foreach ($api->accounts()->statuses('106612343490709443') as $status) { echo $status->content(); } # Note: In case you obtained login-level access, you may omit the ID parameter, which gives back your own account's statuses, like so: foreach ($api->accounts()->statuses() as $status) { echo $status->content(); } # Fetch followers foreach ($api->accounts()->followers('106612343490709443') as $follower) { echo $follower->displayName(); } # View your timelines $timelines = $api->timelines(); # (1) Public timeline var_dump($timelines->public()); # (2) Home timeline (= accounts you are following) var_dump($timelines->home()); # Fetch information about your instance var_dump($api->instance()->get()); # ... enjoy playing with Mastodon's API!
Note: In most cases, using $api->logIn() will be enough. You may then view other people's statuses, etc as well as your own by providing your account ID as parameter as shown above.
.. but I need more docs!
First, have a look at the docs.
Now, all API methods match their URL counterparts:
mastodon.example/api/v1/accounts/:idbecomes$api->accounts()->get($id)mastodon.example/api/v1/accounts/:id/statusesbecomes$api->accounts()->statuses($id)mastodon.example/api/v1/timelines/homebecomes$api->timelines()->home()mastodon.example/api/v1/statuses/:idbecomes$api->statuses()->get($id)
.. same goes for the resulting API entities you get back. For example, the Status entity methods match their array counterparts as found in the docs (only camelcased):
idmay be accessed with$status->id()created_atmay be accessed with$status->createdAt()accountmay be accessed with$status->account()(which in turn gives anAccountentity)
Roadmap
- Add tests
- Add authentication helpers
- Return API entities as individual classes
- Add missing API methods:
- timelines/streaming
- notifications/push
- search
- admin
- Add missing API entities:
- admin/account
- admin/report
- Update empty API entities:
- error
- pushsubscription
- report
- scheduledstatus
Happy coding!
统计信息
- 总下载量: 446
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2021-09-12