I know I can iterate over playlists to compare if a playlist exists on Youtube, but that makes two calls (example below), and since I already know the playlist ID, I just have to make one call.
Two calls on YouTube to play playlists (not the way I want to do this):
# Playlist ID from URL $playlist=$_GET['playlist'];
I have code that works for a single call, but I canβt figure out how to get the 404 error that it returns if the playlist id does not exist (YouTube results below).
YouTube Method ( PlaylistItems ):
public function PlaylistItems($playlist_id, $part='snippet') {
Single call code:
# Playlist ID from URL $playlist=$_GET['playlist'];
Return from the PlaylistItems Method
Google_ServiceException Object ( [errors:protected] => Array ( [0] => Array ( [domain] => youtube.playlistItem [reason] => playlistNotFound [message] => Not Found [locationType] => parameter [location] => playlistId ) ) [message:protected] => Error calling GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLD2D6E64D9CD49E1&key=AIzaSyDVGJhk7DfKKJAaciX14aqyw_YbPaT4fp4: (404) Not Found [string:Exception:private] => [code:protected] => 404 [file:protected] => /Volumes/Coding/WebDev/CWIS/cwis.org/application/modules/Social/Google/io/Google_REST.php [line:protected] => 66 [trace:Exception:private] => Array ( [0] => Array ( [file] => /Volumes/Coding/WebDev/CWIS/cwis.org/application/modules/Social/Google/io/Google_REST.php [line] => 36 [function] => decodeHttpResponse [class] => Google_REST [type] => :: [args] => Array ( [0] => Google_HttpRequest Object ( [batchHeaders:Google_HttpRequest:private] => Array ( [Content-Type] => application/http [Content-Transfer-Encoding] => binary [MIME-Version] => 1.0 [Content-Length] => ) [url:protected] => https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLD2D6E64D9CD49E1&key=AIzaSyDVGJhk7DfKKJAaciX14aqyw_YbPaT4fp4 [requestMethod:protected] => GET [requestHeaders:protected] => Array ( ) [postBody:protected] => [userAgent:protected] => google-api-php-client/0.6.0 [responseHttpCode:protected] => 404 [responseHeaders:protected] => Array ( [content-type] => application/json; charset=UTF-8 [date] => Thu, 18 Jul 2013 05:11:11 GMT [expires] => Thu, 18 Jul 2013 05:11:11 GMT [cache-control] => private, max-age=0 [x-content-type-options] => nosniff [x-frame-options] => SAMEORIGIN [x-xss-protection] => 1; mode=block [server] => GSE [transfer-encoding] => chunked ) [responseBody:protected] => { "error": { "errors": [ { "domain": "youtube.playlistItem", "reason": "playlistNotFound", "message": "Not Found", "locationType": "parameter", "location": "playlistId" } ], "code": 404, "message": "Not Found" } } [accessKey] => ) ) ) [1] => Array ( [file] => /Volumes/Coding/WebDev/CWIS/cwis.org/application/modules/Social/Google/service/Google_ServiceResource.php [line] => 186 [function] => execute [class] => Google_REST [type] => :: [args] => Array ( [0] => Google_HttpRequest Object ( [batchHeaders:Google_HttpRequest:private] => Array ( [Content-Type] => application/http [Content-Transfer-Encoding] => binary [MIME-Version] => 1.0 [Content-Length] => ) [url:protected] => https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=PLD2D6E64D9CD49E1&key=AIzaSyDVGJhk7DfKKJAaciX14aqyw_YbPaT4fp4 [requestMethod:protected] => GET [requestHeaders:protected] => Array ( ) [postBody:protected] => [userAgent:protected] => google-api-php-client/0.6.0 [responseHttpCode:protected] => 404 [responseHeaders:protected] => Array ( [content-type] => application/json; charset=UTF-8 [date] => Thu, 18 Jul 2013 05:11:11 GMT [expires] => Thu, 18 Jul 2013 05:11:11 GMT [cache-control] => private, max-age=0 [x-content-type-options] => nosniff [x-frame-options] => SAMEORIGIN [x-xss-protection] => 1; mode=block [server] => GSE [transfer-encoding] => chunked ) [responseBody:protected] => { "error": { "errors": [ { "domain": "youtube.playlistItem", "reason": "playlistNotFound", "message": "Not Found", "locationType": "parameter", "location": "playlistId" } ], "code": 404, "message": "Not Found" } } [accessKey] => ) ) ) [2] => Array ( [file] => /Volumes/Coding/WebDev/CWIS/cwis.org/application/modules/Social/Google/contrib/Google_YoutubeService.php [line] => 425 [function] => __call [class] => Google_ServiceResource [type] => -> [args] => Array ( [0] => list [1] => Array ( [0] => Array ( [part] => snippet [maxResults] => 50 [playlistId] => PLD2D6E64D9CD49E1 ) ) ) ) [3] => Array ( [file] => /Volumes/Coding/WebDev/CWIS/cwis.org/application/modules/Media/YouTube.php [line] => 412 [function] => listPlaylistItems [class] => Google_PlaylistItemsServiceResource [type] => -> [args] => Array ( [0] => snippet [1] => Array ( [maxResults] => 50 [playlistId] => PLD2D6E64D9CD49E1 ) ) ) [4] => Array ( [file] => /Volumes/Coding/WebDev/CWIS/cwis.org/application/modules/Media/Video.php [line] => 1130 [function] => PlaylistItems [class] => YouTube [type] => -> [args] => Array ( [0] => PLD2D6E64D9CD49E1 ) ) [5] => Array ( [file] => /Volumes/Coding/WebDev/CWIS/cwis.org/public/media/video/index.php [line] => 59 [function] => displayVideoFeed [class] => Video [type] => -> [args] => Array ( ) ) ) [previous:Exception:private] => )
As you can see, all this is either protected or private , since I have to know if there was an error or not?