Skip to content

KKBOX/OpenAPI-PHP

Repository files navigation

KKBOX Open API PHP SDK

Actions Status

The project helps you to access KKBOX's Open API using PHP programming languages.

Installation

You can install the package by using Composer.

composer require kkbox/kkboxopenapi kkbox/kkboxopenapi

To use the development version, please add to your composer.json.

{
  "require": {
    "kkbox/kkboxopenapi": "dev-master"
  },
  "repositories": [
    {
      "type": "vcs",
      "url": "git@github.com:kkbox/OpenAPI-PHP.git"
    }
  ]
}

And then run composer install.

Usage

instantiation

To start using the SDK, you need to register your app in KKBOX's developer site and obtain a valid client ID and client secret. Then, you can create an instance of OpenAPI.

use KKBOX\KKBOXOpenAPI\OpenAPI;

$clientID = 'YOUR_CLIENT_ID';
$clientSecret = 'YOUR_CLIENT_SECRET';
$openAPI = new OpenAPI($clientID, $clientSecret);

Fetch Access Token

Before doing API calls, you need to fetch an access token at first.

$openAPI->fetchAndUpdateAccessToken();

API Calls

When you are ready, you can make API calls like to search, or to fetch information of tracks like

$response = $openAPI->search('Love');

The SDK adopts Guzzle HTTP client, and the response objects conform to PSR-7 HTTP message interfaces. So, if you want to get the JSON objects from the API response, you may have code like

$response = $openAPI->search('Love');
$searchResults = json_decode($response->getBody());
var_dump($searchResults->tracks->data);

Test the Package

Just run vendor/bin/phpunit.

License

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

    http://www.apache.org/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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages