0

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.

2
  • 2
    You passed json_decode true as a second param, so things are arrays,not objects. Commented Jun 17, 2016 at 15:41
  • What's the output of var_dump on $data, and each child of it? When you say you're not getting anything, what do you mean? Commented Jun 17, 2016 at 15:42

1 Answer 1

3

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'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.