0

Ever since Google changed YouTube to API3.0 I can't fetch videos anymore. I can't get video id and api key to apiURL

$video_id = // I stript it from url
$apiKey = Configure::read('YouTube.v3.0.privateKey'); // hidden in bootstrap


$apiURL = 'https://www.googleapis.com/youtube/v3/videos?id=$video_id&key=$apiKey';

and on debug($apiURL); I'm getting

https://www.googleapis.com/youtube/v3/videos?id=$video_id&key=$apiKey

anyone can help? Thanks in Advance.

filype
  • 8,034
  • 10
  • 40
  • 66
Xach Kaa
  • 69
  • 1
  • 9

2 Answers2

1

if you want little snippet, here we go, it works for me on cakephp1.3 application

$apiURL = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id={$video_id}&key={$apiKey}");

$youtubeResponse = json_decode($apiURL, true);

$youtube_data = $youtubeResponse['items'];
// debug($youtube_data);

$youtube_data_title =  $youtube_data['0']['snippet']['title'];
$youtube_data_description = $youtube_data['0']['snippet']['description'];
$youtube_data_thumbnail = $youtube_data['0']['snippet']['thumbnails']['default']['url'];

    $this->set('youtube_data_title', $youtube_data_title);
    $this->set('youtube_data_description', $youtube_data_description);
    $this->set('youtube_data_thumbnail', $youtube_data_thumbnail);
Xach Kaa
  • 69
  • 1
  • 9
0

PHP does not evaluate variables in single quotes. Your URL should be places in double quotes:

$apiURL = "https://www.googleapis.com/youtube/v3/videos?id=$video_id&key=$apiKey";

to get variables replaced with values.

Here is good read about outputing text in PHP

Community
  • 1
  • 1
Bogdan Kuštan
  • 5,427
  • 1
  • 21
  • 30