arunchaitanyajami/spotify-webapi-sdk
Composer 安装命令:
composer require arunchaitanyajami/spotify-webapi-sdk
包简介
Spotify WebApi PHP Library
README 文档
README
requires php >= 7.2
- Integrated Pagination
- Automated Token Refresh
- Separate Services Files For All Api References
- Guzzle Requests
Installation
composer require arunchaitanyajami/spotify-webapi-sdk
Doesnt have token?
Option 1 - Get access token with client credentials
use SpotifyWebApiSdk\SpotifyWebApiSdk;
try {
$spotifyWebApi = new SpotifyWebApiSdk();
$token_obj = $spotifyWebApi->getAccessTokenWithCredentials(
'CLIENT_ID',
'CLIENT_SECRET'
);
echo $token_obj->access_token;
// echo $token_obj->token_type;
// echo $token_obj->expires_in;
} catch(\SpotifyWebAPI\SpotifyWebAPIException $e) {
echo $e->getMessage();
}
Option 2 - Get access token with code authorization (recommended)
Before make requests you must add yours Redirect URIs to https://developer.spotify.com/dashboard
Get redirect url for code:
use SpotifyWebApiSdk\SpotifyWebApiSdk;
try {
$spotifyWebApi = new SpotifyWebApiSdk([
'clientId' => 'CLIENT_ID',
'clientSecret' => 'CLIENT_SECRET',
]);
$callBackUrl = 'http://yoursite.com/callback';
$url = $spotifyWebApi->getUrlForCodeToken($callBackUrl);
header("Location: {$url}");
} catch(\SpotifyWebAPI\SpotifyWebAPIException $e) {
echo $e->getMessage();
}
After signup in spotify you will be redirected back to provided above callback url (http://yoursite.com/callback) with parameter $_GET['code'] with the code that can get token with following command:
use SpotifyWebApiSdk\SpotifyWebApiSdk;
try {
$spotifyWebApi = new SpotifyWebApiSdk();
$tokens = $spotifyWebApi->getAccessTokenWithCode(
'YOUR_CODE',
'http://yoursite.com/callback'
);
} catch(\SpotifyWebAPI\SpotifyWebAPIException $e) {
echo $e->getMessage();
}
And you will receive array with accessToken and refreshToken in the example above $tokens.
Access/Refresh Tokens
Spotify tokens are valid 1 hour. If your token is expired and you make a call, the sdk auto renew access token with provided refresh token in every query (as there is no safe place to automatically save it).
If you set $spotifyWebApi->returnNewTokenIfIsExpired(true); before your request calls, if access token is expired will be returned from the query, object with the new access_token, then you can save it in database and recall request with a fresh Access token. You can also generate access token with refresh token manually with
use SpotifyWebApiSdk\SpotifyWebApiSdk;
try {
$spotifyWebApi = new SpotifyWebApiSdk([
'clientId' => 'CLIENT_ID',
'clientSecret' => 'CLIENT_SECRET',
'accessToken' => $oldAccessToken,
'refreshToken' => 'REFRESH_TOKEN',
]);
$result = $spotifyWebApi->refreshAccessToken();
} catch(\SpotifyWebAPI\SpotifyWebAPIException $e) {
echo $e->getMessage();
}
and save final expire timestamp with time() + $result->expires_in. You can manualy generate new access token every time when saved in your database expired time is end.
Suggestions
It is good practise to add ip of the api that you call in the hosts file in yours server os because Guzzle sometime cannot resolve the dns.
Can increase your execution time of scripts ini_set('max_execution_time', XXX); and set_time_limit(XXX);
arunchaitanyajami/spotify-webapi-sdk 适用场景与选型建议
arunchaitanyajami/spotify-webapi-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「spotify」 「spotify-api」 「spotify-web-api」 「spotify-php-sdk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arunchaitanyajami/spotify-webapi-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arunchaitanyajami/spotify-webapi-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arunchaitanyajami/spotify-webapi-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel wrapper for the Spotify Web API
Easy Spotify Api interface for Symfony2 projects
PHP Package for the (unofficial) Spotify Artists API
PHP Package for logging in to Spotify
Symfony bundle for the Spotify Web API — streaming, music data & integration made easy
Spotify WebApi PHP Library
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-18