{"id":15022999,"url":"https://github.com/duukkis/maphpodon","last_synced_at":"2026-01-21T01:32:10.315Z","repository":{"id":65795327,"uuid":"598104295","full_name":"duukkis/maphpodon","owner":"duukkis","description":"PHP Mastodon client rest api","archived":false,"fork":false,"pushed_at":"2023-02-19T11:35:27.000Z","size":86,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-16T13:07:42.739Z","etag":null,"topics":["api-client","api-wrapper","mastodon","php","rest","rest-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/duukkis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-02-06T12:10:16.000Z","updated_at":"2023-02-19T11:49:49.000Z","dependencies_parsed_at":"2023-02-22T09:31:05.436Z","dependency_job_id":null,"html_url":"https://github.com/duukkis/maphpodon","commit_stats":{"total_commits":62,"total_committers":1,"mean_commits":62.0,"dds":0.0,"last_synced_commit":"84d9d52c368696ce5ecba78aad6b9ca92ea4b202"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/duukkis/maphpodon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duukkis%2Fmaphpodon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duukkis%2Fmaphpodon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duukkis%2Fmaphpodon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duukkis%2Fmaphpodon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duukkis","download_url":"https://codeload.github.com/duukkis/maphpodon/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duukkis%2Fmaphpodon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28004518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","api-wrapper","mastodon","php","rest","rest-api"],"created_at":"2024-09-24T19:58:37.461Z","updated_at":"2026-01-21T01:32:10.297Z","avatar_url":"https://github.com/duukkis.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Maphpodon\n\nPHP client-api for Mastodon. https://docs.joinmastodon.org/ has the api-methods documented.\nAll the entities functions have a link to corresponding documentation.\n\n## Install\n```\ncomposer require duukkis/maphpodon\n```\n\n## Usage\n\n```\ninclude('../vendor/autoload.php');\n\nuse Maphpodon\\Maphpodon;\n\n$masto = new Maphpodon(\n    \"mastobotti.eu\",\n    \"CLIENT_ID\",\n    \"CLIENT_SECRET\",\n    \"ALL_YOU_NEED_IS_AUTH_TOKEN\",\n);\n\n####### Timelines\n$result = $masto-\u003etimelines()-\u003epublic([\"limit\" =\u003e 10]);\n/** @var \\Maphpodon\\models\\Status $status */\nforeach ($result as $i =\u003e $status) {\n    print \"User \" . $status-\u003eaccount-\u003eusername . \n    \" posted at \" . $status-\u003ecreated_at-\u003eformat(\"Y-m-d. H:i\") . \n    \" this \" .$status-\u003econtent . PHP_EOL;\n}\n$result = $masto-\u003etimelines()-\u003ehome([\"limit\" =\u003e 2]);\n$result = $masto-\u003etimelines()-\u003etag(\"fish\");\n\n####### Statuses\n$result = $masto-\u003estatuses()-\u003epost([\"status\" =\u003e \"testi\"]);\n$result = $masto-\u003estatuses()-\u003eget($result-\u003eid);\n$result = $masto-\u003estatuses()-\u003eget(\"109825403503402367\");\n$result = $masto-\u003estatuses()-\u003edelete(\"109823185566762882\");\n$result = $masto-\u003estatuses()-\u003ereblogged_by(\"109825461095585733\");\n$result = $masto-\u003estatuses()-\u003efavourited_by(\"109825461095585733\");\n\n####### Poll\n$result = $masto-\u003estatuses()-\u003epost(\n    [\n        \"status\" =\u003e \"What is the best way to make a poll?\",\n        \"poll\" =\u003e [\n            \"options\" =\u003e [\n                \"This way\",\n                \"Some other way\"\n            ],\n            \"expires_in\" =\u003e 60 * 60,\n            \"multiple\" =\u003e false,\n        ]\n    ]\n);\n$result = $masto-\u003epolls()-\u003eget(\"5\");\n$result = $masto-\u003epolls()-\u003evote(\"5\", [\"choices\" =\u003e [0, 1]]);\n\n####### Remote status favourite\n// find a remote post, use resolve true! so it gets federated to local instance\n$result = $masto-\u003esearch()-\u003eget([\"q\" =\u003e \"https://mas.to/@duukkis/109818862518591984\", \"resolve\" =\u003e true]);\n/** @var \\Maphpodon\\models\\Status $status */\n$status = $result-\u003estatuses[0];\n$result = $masto-\u003estatuses()-\u003efavourite($status-\u003eid);\n\n####### Media handling\n$result = $masto-\u003emedia()-\u003epost(\"./IMG_6298.jpg\", \"description of somesort\", null]);\n$result = $masto-\u003emedia()-\u003eget(\"109825314440397270\");\n####### post with media\n$result = $masto-\u003estatuses()-\u003epost([\"status\" =\u003e \"dippa\", \"media_ids\" =\u003e [\"109825314440397270\"]]);\n\n####### Notifications\n$result = $masto-\u003enotifications()-\u003eindex();\n$result = $masto-\u003enotifications()-\u003eget(\"1\");\n$masto-\u003enotifications()-\u003edismiss(\"1\");\n$masto-\u003enotifications()-\u003eclear();\n\n####### Instance\n$result = $masto-\u003einstance()-\u003eindex();\n\n####### Accounts\n$result = $masto-\u003eaccounts()-\u003eget(\"109807809719057795\");\n$result = $masto-\u003eaccounts()-\u003estatuses(\"109807809719057795\", [\"min_id\" =\u003e \"109816527054798413\", \"limit\" =\u003e 4]);\n$result = $masto-\u003eaccounts()-\u003efollowers(\"109807809719057795\", [\"limit\" =\u003e 2]);\n$result = $masto-\u003eaccounts()-\u003efeatured_tags(\"109807491887075545\", []);\n$result = $masto-\u003eaccounts()-\u003elists(\"109817168119540210\", []);\n$result = $masto-\u003eaccounts()-\u003efollow(\"109817168119540210\");\n$result = $masto-\u003eaccounts()-\u003eunfollow(\"109817168119540210\");\n$result = $masto-\u003eaccounts()-\u003epin/unpin/block/unblock/...(\"109817168119540210\");\n$result = $masto-\u003eaccounts()-\u003enote(\"109817168119540210\", [\"comment\" =\u003e \"api test\"]);\n$result = $masto-\u003eaccounts()-\u003enote(\"109817168119540210\"); // remove comment\n$result = $masto-\u003eaccounts()-\u003esearch([\"q\" =\u003e \"päivän\"]);\n$result = $masto-\u003eaccounts()-\u003elookup([\"acct\" =\u003e \"duukkis\"]);\n// these gave me 500, so something there or then it's just my instance\n$result = $masto-\u003eaccounts()-\u003erelationships([\"id\" =\u003e [\"109817168119540210\", \"109813823501112312\"]]);\n$result = $masto-\u003eaccounts()-\u003efamiliar_followers([\"id\" =\u003e [\"109817168119540210\", \"109813823501112312\"]]);\n\n####### Oauth token fetching\n\n// just put in a ID and secret\n$masto = new Maphpodon(\n    \"mastobotti.eu\",\n    \"CLIENT_ID\",\n    \"CLIENT_SECRET\",\n);\n\n// this will return an url where to redirect customer\n$result = $masto-\u003eauth()-\u003eauthorize(\n    \"read\",\n    \"urn:ietf:wg:oauth:2.0:oob\",\n    \"false\",\n    \"en\"\n);\nprint $result . PHP_EOL;\n// or header(\"Location: \" . $result); exit();\n\n# After user has clicked ok or returned to actual return url given above, you get authorization code in \u0026code param\n# THIS IS DIFFERENT FROM AUTH_TOKEN so we need to fetch the token with below method\n\n$result = $masto-\u003eauth()-\u003etoken(\n    [\n        \"grant_type\" =\u003e \"authorization_code\",\n        \"code\" =\u003e \"AUTHORIZATION_CODE_FROM_ABOVE\",\n        \"client_id\" =\u003e $masto-\u003eclientKey,\n        \"client_secret\" =\u003e $masto-\u003eclientSecret,\n        \"redirect_uri\" =\u003e \"urn:ietf:wg:oauth:2.0:oob\",\n        \"scope\" =\u003e \"read\",\n    ]\n);\n/*\nprint_r($result);\n\nMaphpodon\\models\\Token Object\n(\n    [access_token] =\u003e HERE-IS-A-TOKEN-YOU-CAN-USE\n    [token_type] =\u003e Bearer\n    [scope] =\u003e read\n    [created_at] =\u003e 1675972651\n)\n*/\n$result = $masto-\u003eauth()-\u003erevoke(\n    [\n        \"client_id\" =\u003e $masto-\u003eclientKey,\n        \"client_secret\" =\u003e $masto-\u003eclientSecret,\n        \"token\" =\u003e \"HERE-IS-A-TOKEN-YOU-CAN-USE\",\n    ]\n);\n\n####### Apps\n$result = $masto-\u003eapps()-\u003epost(\n    [\n        \"client_name\" =\u003e \"Duukkis new Api client\",\n        \"redirect_uris\" =\u003e \"urn:ietf:wg:oauth:2.0:oob\",\n        \"scopes\" =\u003e \"read follow write:lists\",\n        \"website\" =\u003e \"https://github.com/duukkis/maphpodon\",\n    ]\n);\n$result = $masto-\u003eapps()-\u003everify_credentials();\n\n####### Admin\n$result = $masto-\u003eadmin()-\u003eaccounts()-\u003eviewV1([\"limit\" =\u003e 2]);\n$result = $masto-\u003eadmin()-\u003eaccounts()-\u003eviewV2([\"status\" =\u003e \"active\", \"limit\" =\u003e 2]);\n$result = $masto-\u003eadmin()-\u003eaccounts()-\u003eview(\"109807491887075545\");\n$result = $masto-\u003eadmin()-\u003eaccounts()-\u003eapprove(\"109807491887075545\");\n$masto-\u003eadmin()-\u003eaccounts()-\u003eaction(\"109807491887075545\", [\"type\" =\u003e \"none\"]);\n// reject, delete, enable, unsilence, unsuspend, unsensitive\n\n$result = $masto-\u003eadmin()-\u003edomain_allows()-\u003elist([]);\n$result = $masto-\u003eadmin()-\u003edomain_blocks()-\u003elist([]);\n$result = $masto-\u003eadmin()-\u003eip_blocks()-\u003elist();\n$result = $masto-\u003eadmin()-\u003eip_blocks()-\u003eview(\"1\");\n$result = $masto-\u003eadmin()-\u003eip_blocks()-\u003ecreate([\"...\"]);\n$result = $masto-\u003eadmin()-\u003eip_blocks()-\u003eupdate(\"1\", [\"...\"]);\n$masto-\u003eadmin()-\u003eip_blocks()-\u003edelete(\"1\");\n\n$result = $masto-\u003eadmin()-\u003ereports()-\u003elist([]);\n$result = $masto-\u003eadmin()-\u003ereports()-\u003eview(\"2\");\n$result = $masto-\u003eadmin()-\u003ereports()-\u003eassign_to_self(\"2\");\n$result = $masto-\u003eadmin()-\u003ereports()-\u003eunassign(\"2\");\n$result = $masto-\u003eadmin()-\u003ereports()-\u003eresolve(\"2\");\n$result = $masto-\u003eadmin()-\u003ereports()-\u003ereopen(\"2\");\n\n$result = $masto-\u003eadmin()-\u003etrends()-\u003estatuses([]);\n$result = $masto-\u003eadmin()-\u003etrends()-\u003elinks([]);\n$result = $masto-\u003eadmin()-\u003etrends()-\u003etags([]);\n\n$result = $masto-\u003eadmin()-\u003ecanonical_email_blocks()-\u003elist();\n$result = $masto-\u003eadmin()-\u003edimensions()-\u003elist([\"keys\" =\u003e [\"languages\", \"sources\", \"servers\", \"space_usage\", \"software_versions\"]]);\n$result = $masto-\u003eadmin()-\u003emeasures()-\u003elist(\n    [\n        \"keys\" =\u003e [\"active_users\", \"new_users\"],\n        \"start_at\" =\u003e \\Carbon\\Carbon::now()-\u003esubMonth()-\u003eformat(\"Y-m-d\"),\n        \"end_at\" =\u003e \\Carbon\\Carbon::now()-\u003eformat(\"Y-m-d\"),\n    ]\n);\n\n```\n\n# Structure of code\n\n## Instances\n\nMethods return either Model, array or just void.\n\n```\nclass Accounts\n{\n    // takes in the Maphpodon wrapper with GuzzleClient\n    public function __construct(protected Maphpodon $maphpodon)\n    {\n    }\n    \n     /**\n     * @link https://docs.joinmastodon.org/methods/accounts/#get\n     * @param string $id\n     * @return Account\n     */\n    public function get(string $id): Model|Account\n    {\n        return Mapper::mapJsonObjectToClass(\n            $this-\u003emaphpodon-\u003eget(sprintf('v1/accounts/%s', $id), []),\n            new Account()\n        );\n    }\n    \n    /**\n     * @link https://docs.joinmastodon.org/methods/accounts/#statuses\n     * @param string $id\n     * @param array $params\n     * @return Status[]\n     */\n    public function statuses(string $id, array $params = []): array\n    {\n        return Mapper::mapJsonObjectToClassArray(\n            $this-\u003emaphpodon-\u003eget(sprintf('v1/accounts/%s/statuses', $id), [\"query\" =\u003e $params]),\n            new Status()\n        );\n    }\n```\n\n## Models\n\nThe returning objects are mapped into models.\n```\nclass Status extends Model\n{\n    // not nullable\n    public string $id;\n    // Carbon::parse\n    public Carbon $created_at;\n    // can be null\n    public ?string $in_reply_to_id;\n    public bool $sensitive;\n    // this is mapped to Application model\n    public Application $application;\n    // check if we have mapper in $mapArrayToObjects and map array to those\n    public array $media_attachments = [];\n    // we have no mapper for this, just put json-objects to array\n    public array $emojis = [];\n    \n    public array $mapArrayToObjects = [\n        \"media_attachments\" =\u003e MediaAttachment::class,\n```\n## Exceptions\n\nCreated Interface ExceptionCatcher that can be overwritten with any Catcher that handles the GuzzleException. Default will just rethrow the Exception.\nFor an example created DevelopmentExceptionCatcher into helpers dir.\n\n## Testing\n\nThere is a basic phpunit setup.\n\n## Lorem Ipsum\n\nNaming is done according the path. /api/v1/accounts is in entities/Accounts and /api/v1/accounts/follow is a follow function.\n\nHave Fun!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduukkis%2Fmaphpodon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduukkis%2Fmaphpodon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduukkis%2Fmaphpodon/lists"}