I am trying to get the URL of a thumbnail from YouTube's History JSON feed. I have the key and can browse the JSON in my browser.
Feed: http://pastebin.com/mePrYhxK
I can't seem to be able to get anything.
$json = file_get_contents('YouTubeJSONURLincludingkey');
$data = json_decode($json,true);
$url = $data->{'items'}[0]->{'snippet'}->{'thumbnails'}->{'medium'}->{'url'};
echo $url;
Right now, getting nothing.
asked Jun 17, 2016 at 15:40
Cody Raspien
1,9135 gold badges31 silver badges56 bronze badges
1 Answer 1
Passing true to the second argument of json_decode indicates you want it to return an array.
You might be able to get better results doing:
$url = $data['items'][0]['snippet']['thumbnails']['medium']['url'];
answered Jun 17, 2016 at 15:42
Ryan
14.7k9 gold badges68 silver badges104 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-php
json_decodetrueas a second param, so things are arrays,not objects.var_dumpon$data, and each child of it? When you say you're not getting anything, what do you mean?