定制 gerenuk/php-tidal-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gerenuk/php-tidal-api

最新稳定版本:v1.0.0

Composer 安装命令:

composer require gerenuk/php-tidal-api

包简介

A PHP wrapper for Tidal's Api.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is a PHP wrapper for Tidal's API. It is a modified version of jwilsson/spotify-web-api-php.

Warning

This package currently only supports the official Tidal's API endpoints.

Table of Contents

  1. Introduction
  2. Version Compatability
  3. Requirements
  4. Installation
  5. Usage
  6. Changelog
  7. Contributing
  8. Security Vulnerabilities
  9. Credits
  10. License

Version Compatability

Plugin PHP
1.x 8.x

Requirements

Installation

You can install the package via composer:

composer require gerenuk/php-tidal-api

Usage

Before using the Tidal API you will need to create an app at Tidal's developer website.

Simple example to retrieve the currently authenticated user's playlists:

Step 1:

Put the following code in its own file, lets call it auth.php. Replace CLIENT_ID with the value given to you by Tidal. The REDIRECT_URI is the one you entered when creating the Tidal app, make sure it's an exact match. You'll also need to create a code verifier and store it somewhere between requests. It will be used again in the second step.

require 'vendor/autoload.php';

$session = new TidalApi\Session(
    'CLIENT_ID',
    '', // Normally the client secret, but this value can be omitted when using the PKCE flow.
    'REDIRECT_URI'
);

$verifier = $session->generateCodeVerifier(); // Store this value somewhere, a session for example.
$challenge = $session->generateCodeChallenge($verifier);
$state = $session->generateState();

$options = [
    'code_challenge' => $challenge,
    'scope' => [
        'playlists.read',
    ],
    'state' => $state,
];

header('Location: ' . $session->getAuthorizeUrl($options));
die();

Note: The state parameter is optional but highly recommended to prevent CSRF attacks. The value will need to be stored between requests and verified when the user is redirected back to your application from Tidal.

Step 2:

When the user has approved your app, Tidal will redirect the user together with a code to the specified redirect URI. You'll need to use this code to request an access token from Tidal. The code verifier created in the previous step will also be needed.

Note: The API wrapper does not include any token management. It's up to you to save the access token somewhere (in a database, a PHP session, or wherever appropriate for your application) and request a new access token when the old one has expired.

Let's put this code in a new file called callback.php:

require 'vendor/autoload.php';

$session = new TidalApi\Session(
    'CLIENT_ID',
    'CLIENT_SECRET',
    'REDIRECT_URI'
);

$state = $_GET['state'];

// Fetch the stored state value from somewhere. A session for example.

if ($state !== $storedState) {
    // The state returned isn't the same as the one we've stored, we shouldn't continue.
    die('State mismatch');
}

// Request an access token using the code from Tidal and the previously created code verifier.
$session->requestAccessToken($_GET['code'], $verifier);

$accessToken = $session->getAccessToken();
$refreshToken = $session->getRefreshToken();

// Store the access and refresh tokens somewhere. In a session for example.

// Send the user along and fetch some data!
header('Location: app.php');
die();

When requesting an access token, a refresh token will also be included. This can be used to extend the validity of access tokens. It's recommended to also store this somewhere persistent, in a database for example.

Step 3:

In a third file, app.php, tell the API wrapper which access token to use, and then make some API calls!

require 'vendor/autoload.php';

$api = new TidalApi\TidalApi();

// Fetch the saved access token from somewhere. A session for example.
$api->setAccessToken($accessToken);

// It's now possible to request the currently authenticated user's playlists.
print_r(
    $api->getMyPlaylists()
);

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

gerenuk/php-tidal-api 适用场景与选型建议

gerenuk/php-tidal-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Tidal」 「Gerenuk」 「tidal-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gerenuk/php-tidal-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gerenuk/php-tidal-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 gerenuk/php-tidal-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-09