simivar / genius-php
Genius PHP 是一个开源库,允许您从 PHP 应用程序访问 Genius API。支持所有资源。
3.0.0
2021-05-12 16:56 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- myclabs/php-enum: ^1.8
- php-http/client-common: ^2.0
- php-http/discovery: ^1.13
- php-http/httplug: ^2.0
- php-http/message: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- guzzlehttp/guzzle: ^7.3
- guzzlehttp/psr7: ^1.8
- http-interop/http-factory-guzzle: ^1.0
- php-http/guzzle7-adapter: ^1.0
- phpstan/phpstan: ^0.12.85
- phpstan/phpstan-phpunit: ^0.12.18
- phpunit/phpunit: ^8.5
README
Genius PHP 是一个开源库,允许您从 PHP 应用程序访问 Genius API。从 1.0 版本开始支持 OAuth 2。
入门
Genius PHP 通过 Composer 提供。1.0 版本不再实现自己的 HTTP 客户端,而是使用 HTTPlug 抽象,因此您可以自由选择任何依赖 php-http/client-implementation 虚拟包 的 HTTP 客户端。
composer require simivar/genius-php php-http/message php-http/guzzle6-adapter
静态 Bearer 示例
<?php require_once('vendor/autoload.php'); $authentication = new \Http\Message\Authentication\Bearer('YOUR_ACCESS_TOKEN'); $genius = new \Genius\Genius($authentication); $upvoteAnnotation = $genius->getAnnotationsResource()->get(11852248);
OAuth2 示例
require_once('vendor/autoload.php'); $authentication = new \Genius\Authentication\OAuth2( 'YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', new \Genius\Authentication\ScopeList([ \Genius\Enum\Scope::ME(), \Genius\Enum\Scope::CREATE_ANNOTATION(), \Genius\Enum\Scope::MANAGE_ANNOTATION(), \Genius\Enum\Scope::VOTE(), ]), null ); $accessTokenFromDatabase = 'get access token from DataBase here'; if ($accessTokenFromDatabase === null) { $authorizeUrl = $authentication->getAuthorizeUrl(); // redirect user to $authorizeUrl } else { $authentication->setAccessToken($accessTokenFromDatabase); } $genius = new \Genius\Genius($authentication); $upvoteAnnotation = $genius->getAnnotationsResource()->get(11852248);
完整文档、安装说明和示例可在: http://simivar.github.io/Genius-PHP/ 查看。
版本控制
Genius PHP 使用 Semver 创建。所有次要和补丁更新都是向后兼容的。 0.1
分支不再维护。
许可证
有关更多信息,请参阅 许可证文件。