0

I am trying to get some information about YouTube channel's from the YouTube API.

This is an example the output (using Google's channel), http://gdata.youtube.com/feeds/api/users/Google?alt=json

I am getting the JSON using this:

$json = file_get_contents("http://gdata.youtube.com/feeds/api/users/Google?alt=json");
$data = json_decode($json, true);

I uploaded the output of var_dump($data); to pastebin: http://pastebin.com/CWA7YYGi

What I want to get is totalUploadViews from yt$statistics.

What I have tried so far is:

echo $data['yt$statistics']['totalUploadViews'];

But this gives me an error: Notice: Undefined index: yt$statistics

Not sure what I am doing wrong, would appreciate the help.

3 Answers 3

2

yt$statistics is itself a value of a parent array. Try

$data['entry']['yt$statistics']['totalUploadViews'];
Sign up to request clarification or add additional context in comments.

Comments

1

The yt$statistics is a key in the array of $data['entry'].

Comments

0

do this:

$json = file_get_contents("http://gdata.youtube.com/feeds/api/users/Google?alt=json");
$data = json_decode($json, true);
echo $data["entry"]["yt\$statistics"]["totalUploadViews"];

the "\$" just escapes the harmful $ from parsing.

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.