1
votes

I need help with obtaining channel name (title). I want to do it with json_decode but I don't know how. Please help me :) Thank you :)

https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername=$youtubechannel&key=YOUR_KEY&getJSON

$url="https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername=$youtubechannel&key=YOUR_KEY&getJSON";
$json = file_get_contents($url);
$json_result = json_decode($json, TRUE);
$raw_channel_name =  $json_result->results[0];
$channel_name = $raw_channel_name->title;
echo $channel_name;
1

1 Answers

0
votes

Sincerely I prefer to use CURL instead of "file_get_contents", it's more flexible.

About json_decode, if you want to work with an object then get rid of second parameter. "YES" parameter forces the result as ARRAY not object.

json_decode($json)

if you use second param then:

$result = json_decode($json,YES) 

var_dump($result);

You will see an array.