chipslays / telegraph
Telegraph API 客户端 for PHP
3.0.1
2022-10-24 04:49 UTC
Requires (Dev)
- symfony/var-dumper: ^6.1
README
Telegraph 是一个匿名博客平台,由 Telegram 创建的免费发布工具。
安装
使用 Composer 安装最新 3.x 版本。
composer require chipslays/telegraph
使用方法
简单模式
$client = new Telegraph\Client; $account = $client->createAccount('johndoe', 'John Doe', 'https://example.com'); $page = $account->createPage('Hello World', 'This is a Hello World example.'); echo $page->getUrl(); // https://telegra.ph/Hello-World-10-21-12
困难模式
use Telegraph\Client; use Telegraph\Element; use Telegraph\File; use Telegraph\Types\Account; use Telegraph\Types\NodeElement; $client = new Client; $account = $client->createAccount('johndoe', 'John Doe', 'https://example.com'); $page = $account->createPage( 'Rich Example', [ Element::text("Line 1\nLine 2\nLine 3\n\n"), Element::line(), Element::bigHeading("H3 text"), Element::smallHeading("H4 text"), Element::line(), Element::strongText("Strong text\n"), Element::italicText("Itaic text\n"), Element::underlineText("Underline text\n"), Element::strikeText("Strike text\n"), Element::emphasizedText("Em text\n"), Element::code("Code text\n"), Element::link("This is link\n", 'https://github.com/chipslays/telegraph'), Element::space(), // add a new line otherwise the previous tags will be in heading new NodeElement('h3', [new NodeElement('a', 'This is link in title, wow!', ['href' => '#'])]), Element::space(), // add a new line otherwise the previous tags will be in blockquote Element::blockquote("Blockquote text\n"), Element::line(), Element::pre("echo 'Hello Pre Text!';"), Element::line(), Element::smallHeading("Items List"), Element::list(['Item 1', 'Item 2', 'Item 3']), Element::smallHeading("Numeric List"), Element::list(['Item 1', 'Item 2', 'Item 3'], true), Element::line(), Element::image('https://images.unsplash.com/photo-1541963463532-d68292c34b19?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8Mnx8fGVufDB8fHx8&w=1000&q=80', 'Image Caption'), // Element::image(File::upload('/path/to/local/image.jpg')), Element::line(), Element::smallHeading("Embed Blocks"), Element::youtube('https://www.youtube.com/watch?v=dQw4w9WgXcQ', 'Youtube Caption'), Element::vimeo('https://vimeo.com/340057344', 'Vimeo Caption'), Element::twitter('https://twitter.com/elonmusk/status/1354174279894642703', 'GAMESTONK!!1!1'), // Element::embed('vendorName', 'https://example.com', 'Universal method for embed.'), ], ); echo $page->getUrl(); // https://telegra.ph/Rich-Example-10-21
上传文件到 Telegraph 服务器。
use Telegraph\File; // Returns string $imageUrl = File::upload('/path/to/local/image.jpg'); // Can pass url $imageUrl = File::upload('https://example.com/image.jpg'); // Returns array with preserved keys // ['my_nudes' => 'https://telegra.ph/*, ....] $imageUrl = File::upload([ 'my_nudes' => '/path/to/local/image.jpg', 'home_video_with_my_gf' => '/path/to/local/video.mp4', ]);
示例
您可以在 这里 找到示例。
在这里 几乎涵盖了所有 流行的使用场景 的 Telegraph API。
文档
未找到。
所以,编写良好的文档,Client
类支持 Telegraph API 的所有方法,只需开始键入,例如 $client->createAccount(...)
,然后您的 IDE 会帮助您。
使用 Element
辅助类创建丰富内容,或使用更灵活的 NodeElement
。
Element
类在内部使用 NodeElement
。
在这里查看它是如何工作的 这里。
祝你好运,陌生人。
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 获取更多信息。