1

私は Drupal を使用しており、teamliquid.net で行うように、ユーザー ストリームが表示されるブロックを追加したいと考えています。

そのため、通常の作業を行い、ユーザーにフィールドを追加して、Twitch-ID などを入力できるようにします。

これは私の views-view-fields--streambar--block.tpl.php ファイルです:

    <?php
    $time_pre = microtime(true);
    $channelName = strip_tags($fields['field_streamid']->content);
    $json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName)), true);
    $saveResult = " is Offline";
    $currentViewer = "Offline";
    $game = strip_tags($fields['field_teamuser']->content);
    if ($json_array['stream'] != NULL) {
        $channelTitle = $json_array['stream']['channel']['display_name'];
        $streamTitle = $json_array['stream']['channel']['status'];
        $currentGame = $json_array['stream']['channel']['game'];
        $currentViewer =$json_array['stream']['viewers']." Viewers";
        $saveResult = " is Online";
     }
    $time_post = microtime(true);
    $exec_time = $time_post - $time_pre;
    $sec = $exec_time * 1000;
?>
<div class=<?php echo "\"$game streamItem\"" ?> title=<?php echo "\"$currentViewer\"" ?> >
<?php
        print $sec;
        print $fields['name']->content;
        echo "$saveResult";
      ?>
</div>

これまでのところ機能していますが、ウェブサイトの速度が地獄のように遅くなります. それは私のせいですか、それとも API が非常に遅いため、回避策を探す必要がありますか?

4

1 に答える 1