kkbox / kkboxopenapi
KKBOX Open API PHP SDK
1.0.2
2018-06-01 09:18 UTC
Requires
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^6.3
This package is not auto-updated.
Last update: 2024-09-23 06:50:07 UTC
README
该项目帮助您使用PHP编程语言访问KKBOX的Open API。
安装
您可以使用Composer安装此包。
composer require kkbox/kkboxopenapi kkbox/kkboxopenapi
要使用开发版本,请在您的composer.json
中添加。
{ "require": { "kkbox/kkboxopenapi": "dev-master" }, "repositories": [ { "type": "vcs", "url": "git@github.com:kkbox/OpenAPI-PHP.git" } ] }
然后运行composer install
。
用法
实例化
要开始使用SDK,您需要在KKBOX的开发者网站注册您的应用,并获取有效的客户端ID和客户端密钥。然后,您可以创建一个OpenAPI
实例。
use KKBOX\KKBOXOpenAPI\OpenAPI; $clientID = 'YOUR_CLIENT_ID'; $clientSecret = 'YOUR_CLIENT_SECRET'; $openAPI = new OpenAPI($clientID, $clientSecret);
获取访问令牌
在进行API调用之前,您需要首先获取一个访问令牌。
$openAPI->fetchAndUpdateAccessToken();
API调用
准备好后,您可以进行API调用,如搜索,或者获取曲目信息等。
$response = $openAPI->search('Love');
SDK采用Guzzle HTTP客户端,响应对象符合PSR-7 HTTP消息接口。因此,如果您想从API响应中获取JSON对象,您可能会有以下代码:
$response = $openAPI->search('Love'); $searchResults = json_decode($response->getBody()); var_dump($searchResults->tracks->data);
测试包
只需运行vendor/bin/phpunit
。
许可证
Copyright 2018-2019 KKBOX Technologies Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://apache.ac.cn/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.