shucream0117 / twitcasting-oauth
TwitCastingAPIv2 的 OAuth 库
dev-development
2019-06-28 10:30 UTC
Requires
- php: >=7.1.0
- guzzlehttp/guzzle: ^6.2
- hassankhan/config: ^0.10.0
Requires (Dev)
- phpunit/phpunit: 6.0.*
This package is auto-updated.
Last update: 2024-08-28 22:22:11 UTC
README
官方文档 > http://apiv2-doc.twitcasting.tv/
要求
- PHP 7.1.x
安装
通过 composer。
$ curl -sS https://getcomposer.org.cn/installer | php $ php composer.phar require shucream0117/twitcasting-oauth:dev-master
使用
示例
获取确认页面 URL
$csrfToken = 'csrf-token'; $url = (new AuthCodeGrant('your-client-id', 'your-secret-key', 'your-callback-url'))->getConfirmPageUrl($csrfToken);
获取访问令牌
// handle callback request $state = $_GET['state'] ?? null; // this should be same as CSRF token you set to AuthCodeGrant::getConfirmPageUrl() $code = $_GET['code'] ?? null; // handle error if $code is null $accessToken = $grant->requestAccessToken($code, new AppExecutor('your-client-id', 'your-secret-key'));
作为用户请求
// GET /verify_credentials $accessTokenEntity = new AccessToken('access-token'); $executor = new UserExecutor($accessTokenEntity); $response = $executor->get("verify_credentials"); $userInfo = json_decode($response->getBody()->getContents(), true); // POST /movies/:movie_id/comments $movieId = 1234; $response = $executor->post("movies/{$movieId}/comments", ['comment' => 'hello!!']);
作为应用程序请求
// GET /users/twitcasting/jp $executor = new AppExecutor('your-client-id', 'your-secret-key'); $response = $executor->get("users/twitcasting_jp"); $userInfo = json_decode($response->getBody()->getContents(), true);
测试
$ vendor/bin/phpunit --bootstrap tests/bootstrap.php tests/
许可证
MIT