niland/api-client-php

PHPNiland API 客户端

1.2.1 2016-10-11 12:58 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:47:30 UTC


README

设置

要设置项目,请按照以下步骤操作

  1. 通过 Composer 安装包
composer require niland/api-client-php
  1. 接下来,您需要使用您的API密钥初始化客户端。您可以在您的Niland API账户中找到它。
// composer autoload
require __DIR__ . '/vendor/autoload.php';
$client = new \NilandApi\Client(YOUR_API_KEY);

快速开始

使用分页列出曲目

$response = $client->get('tracks', array('page_size' => 10, 'page' => 2));

通过参考值检索曲目

$response = $client->get('tracks/reference/YOUR_REFERENCE');

通过相似性/标签查找曲目

$response = $client->get('tracks/search', array(
    'similar_ids' => array(1234),
    'tag_ids'     => array(21, 41)
));

发布曲目

$response = $client->post('tracks', array(
    'title'     => 'foobar',
    'artist'    => 'foobar',
    'reference' => 'foobar',
    'tags'      => array(21, 41),
    'audio'     => fopen('/path/to/your/audio/file.mp3', 'r')
));

已知问题

如果您在PHP 7中使用URL作为fopen中的参数,您将收到一个400 Bad Request错误。它会生成一个无效的块体错误。

以下示例将生成一个400错误

$response = $client->post('tracks', array(
    'title'     => 'foobar',
    'artist'    => 'foobar',
    'reference' => 'foobar',
    'tags'      => array(21, 41),
    'audio'     => fopen('http://myawesomewebsite.com/file.mp3', 'r')
));