我需要帮助才能获得频道名称(标题)。我想用json_decode
来做,但我不知道如何做。请帮帮我:)谢谢:))
$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;
答案 0 :(得分:0)
真诚地,我更喜欢使用CURL而不是" file_get_contents",它更灵活。
关于json_decode,如果你想使用一个对象,那么摆脱第二个参数。 "是"参数强制结果为ARRAY而不是对象。
json_decode($json)
如果您使用第二个参数:
$result = json_decode($json,YES)
var_dump($result);
你会看到一个数组。