我的代码没有显示 concurrentViewers youtube api
My code don't showing a concurrentViewers youtube api
我无法从 youtube 加载并发查看器 api
我的代码:
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<?php
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet%2Cstatistics%2CliveStreamingDetails&id={ID}&key={KEY}&alt=json");
$JSON_Data = json_decode($JSON);
$views = $JSON_Data->{'entry'}->{'yt$statistics'}->{'liveStreamingDetails'}->{'concurrentViewers'};
echo $views;
?>
您缺少 items
属性。
我假设 JSON_Data
是您用于存储 YouTube API 请求响应的对象。
这相当于 javascript:
JSON_Data.items[0].liveStreamingDetails.concurrentViewers;
您需要更改 PHP 代码以考虑响应的 items
属性 - 我不知道 {'entry'}->{'yt$statistics'}
- 您想要读取的数据是不在响应的那个部分。
我无法从 youtube 加载并发查看器 api
我的代码:
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<?php
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet%2Cstatistics%2CliveStreamingDetails&id={ID}&key={KEY}&alt=json");
$JSON_Data = json_decode($JSON);
$views = $JSON_Data->{'entry'}->{'yt$statistics'}->{'liveStreamingDetails'}->{'concurrentViewers'};
echo $views;
?>
您缺少 items
属性。
我假设 JSON_Data
是您用于存储 YouTube API 请求响应的对象。
这相当于 javascript:
JSON_Data.items[0].liveStreamingDetails.concurrentViewers;
您需要更改 PHP 代码以考虑响应的 items
属性 - 我不知道 {'entry'}->{'yt$statistics'}
- 您想要读取的数据是不在响应的那个部分。