podcasthosting/podcast-client-spotify

在Spotify上创建(添加)和删除播客

v0.12.6-beta 2023-05-22 14:24 UTC

README

通过Composer

$ composer require podcasthosting/podcast-client-spotify

简介

创建(添加)、获取状态、更新URL和在Spotify上删除(删除)播客(DeliveryClient)。

您还可以从不同的Spotify API(AnalyticsClient)获取分析数据。

要使用这些API,您需要成为认证的播客提供商(聚合器)。

文档

DeliveryClient

$auth = new AuthClient($clientId, $clientSecret);
$token = $auth->getToken();

// Initiate client
$client = new Delivery\Client($token->access_token);

// Create podcast entry on Spotify
try {
    $res = $client->create('Example Feed', 'https://example.podcaster.de/feed.rss');
    if ($res instanceof Delivery\Result) {
        // Do something with SpotifyUri
        $spotifyUri = $res->getSpotifyUri(); // Result e.g. spotify:show:123
    }
} catch (AuthException $e) {
} catch (DomainException $e) {
} catch (DuplicateException $e) {
}

// Get status and info for podcast entry on Spotify
try {
    $res = $client->status($spotifyUri);
    if ($res instanceof Result) {
        // A description of the current status of the podcast.
        $statusDescription = $res->getStatusDescription();
        // A list of descriptive validation errors for the podcast
        $validationErrors = $res->getValidationErrors();
    }
} catch (AuthException $e) {
} catch (DomainException $e) {
} catch (NotFoundException $e) {
}

// Update uri for podcast entry on Spotify
try {
    $newUrl = 'https://example.podcaster.de/newfeed.rss';
    $res = $client->status($spotifyUri, $newUrl);
    if (true === $res) {
      // Is updated
    }
} catch (AuthException $e) {
} catch (DomainException $e) {
} catch (NotFoundException $e) {
}

// Remove podcast entry
try {
    $res = $client->remove($spotifyUri);
    if (true === $res) {
      // Is removed
    }    
} catch (AuthException $e) {
} catch (DomainException $e) {
} catch (NotFoundException $e) {
}

AnalyticsClient

$auth = new AuthClient($clientId, $clientSecret);
$token = $auth->getToken();
// Initiate client
$client = new Analytics\Client($token->access_token, $clientId);
// Fetch analytics data from Spotify
try {
    $res = $analyticsClient->get((new \DateTime())->setDate(\DateInterval::createfromdatestring('-1 day')));
    if ($res instanceof Analytics\Result) {
        // Iterate over JSON objects (from json_decode)
        foreach($res->getDecoded() as $jsonObject) {
        }
        // Iterate over raw JSON strings
        foreach($res->getRaw() as $sJson) {
        }
    }     
} catch (AuthException $e) {
}

测试

尚未提供。抱歉。

$ composer test

贡献

您可以在GitHub上找到源代码。欢迎提交补丁。

许可证

MIT许可证(MIT)。请参阅许可证文件获取更多信息。