Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #25 from timezoneone/tzo/fixes
Browse files Browse the repository at this point in the history
Catch uncaught error triggered when youtube id not found.
  • Loading branch information
edlinklater authored Oct 12, 2019
2 parents 39c5afc + c8aeec0 commit 771a474
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions code/YouTubeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public function Field($properties = array())
Requirements::javascript('https://apis.google.com/js/client.js?onload=googleApiClientReady');
} elseif (!empty($this->value) && self::url_parser($this->value)) {
$client = new GuzzleHttp\Client();
$res = $client->get('https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=' . $this->value . '&format=json');
if ($res->getStatusCode() == '200' && $data = json_decode($res->getBody())) {
try {
$res = $client->get('https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=' . $this->value . '&format=json');
} catch (Exception $e) {}
if (isset($res) && $res->getStatusCode() == '200' && $data = json_decode($res->getBody())) {
$api_data = new stdClass();
$api_data->id = $this->value;
$api_data->snippet = new stdClass();
Expand Down

0 comments on commit 771a474

Please sign in to comment.