PHP code example of listennotes / podcast-api
1. Go to this page and download the library: Download listennotes/podcast-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
listennotes / podcast-api example snippets
lerplate to make an api call
try {
define( 'API_KEY', ( getenv( 'API_KEY' ) ? getenv( 'API_KEY' ) : null ) );
$objClient = new ListenNotes\PodcastApi\Client( API_KEY );
$strResponse = $objClient->typeahead( [ 'q' => 'startup', 'show_podcasts' => '1' ] );
$arrHeaders = $objClient->getHeaders();
print("\n=== Some account info ===\n");
printf( "Free Quota this month: %s requests\n" , $arrHeaders['x-listenapi-freequota'] );
printf( "Usage this month: %s requests\n" , $arrHeaders["x-listenapi-usage"] );
printf( "Next billing date: %s\n" , $arrHeaders["x-listenapi-nextbillingdate"] );
print("\n=== Response data ===\n");
print_r( json_decode( $strResponse ) );
} catch ( ListenNotes\PodcastApi\Exception\APIConnectionException $objException ) {
print("Failed to connect to Listen API servers");
} catch ( ListenNotes\PodcastApi\Exception\AuthenticationException $objException ) {
print("Wrong api key, or your account has been suspended!");
} catch ( ListenNotes\PodcastApi\Exception\InvalidRequestException $objException ) {
print("Wrong parameters!");
} catch ( ListenNotes\PodcastApi\Exception\NotFoundException $objException ) {
print("Endpoint not exist or the podcast / episode not exist!");
} catch ( ListenNotes\PodcastApi\Exception\RateLimitException $objException ) {
print("You have reached your quota limit or rate limit!");
} catch ( ListenNotes\PodcastApi\Exception\ListenApiException $objException ) {
print("Something wrong on Listen Notes servers");
} catch ( Exception $e ) {
print("Other errors that may not be related to Listen API");
}
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->search([
'q' => 'star wars',
'sort_by_date' => 0,
'type' => 'episode',
'offset' => 0,
'len_min' => 10,
'len_max' => 30,
'genre_ids' => '68,82',
'published_before' => 1580172454000,
'published_after' => 0,
'only_in' => 'title,description',
'language' => 'English',
'region' => '',
'safe_mode' => 0,
'unique_podcasts' => 0,
'interviews_only' => 0,
'sponsored_only' => 0,
'page_size' => 10
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->typeahead([
'q' => 'star wars',
'show_podcasts' => 1,
'show_genres' => 1,
'safe_mode' => 0
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->searchEpisodeTitles([
'q' => 'Jerusalem Demsas on The Dispossessed'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->spellcheck([
'q' => 'microsft stock'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchRelatedSearches([
'q' => 'evergrande'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchTrendingSearches();
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchBestPodcasts([
'genre_id' => 93,
'page' => 2,
'region' => 'us',
'sort' => 'listen_score',
'safe_mode' => 0
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchPodcastById([
'id' => '4d3fe717742d4963a85562e9f84d8c79',
'next_episode_pub_date' => 1479154463000,
'sort' => 'recent_first'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->deletePodcast([
'id' => '4d3fe717742d4963a85562e9f84d8c79',
'reason' => 'the podcaster wants to delete it'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchEpisodeById([
'id' => '6b6d65930c5a4f71b254465871fed370',
'show_transcript' => 1
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->batchFetchEpisodes([
'ids' => 'c577d55b2b2b483c969fae3ceb58e362,0f34a9099579490993eec9e8c8cebb82'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->batchFetchPodcasts([
'ids' => '3302bc71139541baa46ecb27dbf6071a,68faf62be97149c280ebcc25178aa731,37589a3e121e40debe4cef3d9638932a,9cf19c590ff0484d97b18b329fed0c6a',
'rsses' => 'https://rss.art19.com/recode-decode,https://rss.art19.com/the-daily,https://www.npr.org/rss/podcast.php?id=510331,https://www.npr.org/rss/podcast.php?id=510331',
'itunes_ids' => '1457514703,1386234384,659155419',
'spotify_ids' => '3DDfEsKDIDrTlnPOiG4ZF4,4qDNe5Gvl1XxdLinUGEXrC,23NZCM4ik6o3UYkM473Itz',
'show_latest_episodes' => 1,
'next_episode_pub_date' => 1557394247000
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchCuratedPodcastsListById([
'id' => 'SDFKduyJ47r'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchPodcastGenres([
'top_level_only' => 1
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchPodcastRegions();
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchPodcastLanguages();
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->justListen();
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchCuratedPodcastsLists([
'page' => 2
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchRecommendationsForPodcast([
'id' => '25212ac3c53240a880dd5032e547047b',
'safe_mode' => 0
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchRecommendationsForEpisode([
'id' => '254444fa6cf64a43a95292a70eb6869b',
'safe_mode' => 0
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->submitPodcast([
'rss' => 'https://feeds.megaphone.fm/committed',
'email' => '[email protected] '
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchPlaylistById([
'id' => 'm1pe7z60bsw',
'type' => 'episode_list',
'last_timestamp_ms' => 0,
'sort' => 'recent_added_first'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchMyPlaylists([
'sort' => 'recent_added_first',
'page' => 1
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchAudienceForPodcast([
'id' => '25212ac3c53240a880dd5032e547047b'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->fetchPodcastsByDomain([
'domain_name' => 'nytimes.com',
'page' => 1
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->createPlaylist([
'name' => 'My favorite podcasts',
'description' => 'Podcasts and episodes to revisit.',
'visibility' => 'public',
'type' => 'episode_list'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->updatePlaylist([
'id' => 'm1pe7z60bsw',
'name' => 'My favorite podcasts',
'description' => 'Podcasts and episodes to revisit.',
'visibility' => 'public',
'type' => 'podcast_list'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->deletePlaylist([
'id' => 'm1pe7z60bsw'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->addPlaylistItem([
'id' => 'm1pe7z60bsw',
'episode_id' => 'e53e6992a5b7492f9ea6fcd85d9ad95f',
'notes' => 'Worth a listen.'
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->deletePlaylistItem([
'id' => 'm1pe7z60bsw',
'item_id' => 23
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));
ent = new ListenNotes\PodcastApi\Client(getenv('LISTEN_API_KEY') ?: null);
$response = $client->updatePlaylistItemNotes([
'id' => 'm1pe7z60bsw',
'item_id' => 23,
'notes' => ''
]);
print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR));