Reputation: 153
I'm trying to get a list of youtube videos while searching on a specific keyword.
I've tried the following tutorial : Search by keyword
Unfortunatly it doesn't work.
The following error appears on my screen:
A service error occurred: Error calling GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=amsterdam&maxResults=20&key=PRIVATEKEY: (403) Access Not Configured. Please use Google Developers Console to activate the API for your project.
I have activated the following API's in my console
Am i missing some API's?
I've also enabled billing, but it still isn't working.
A little part of my code:
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$youtube = new Google_YouTubeService($client);
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
));
Upvotes: 2
Views: 5605
Reputation: 83
$DEVELOPER_KEY = '';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$youtube = new Google_YoutubeService($client);
try {
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
));
$videos = '';
$channels = '';
$playlists = '';
foreach ($searchResponse['items'] as $searchResult) {
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videos .= sprintf('<li>%s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['videoId']);
break;
case 'youtube#channel':
$channels .= sprintf('<li>%s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['channelId']);
break;
case 'youtube#playlist':
$playlists .= sprintf('<li>%s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['playlistId']);
break;
}
}
echo ($playlists)
this will be work
Upvotes: 1