前提
Youtube Data Api からデータを取得して表示させたいのですが、クォータ制限があるので、アクセス数が多くなっても対応できるようにしたいです。
発生している問題・エラーメッセージ
表示は問題ないが、APIの更新が多すぎてすぐクォータ上限に達してしまう。
該当のソースコード
PHP
1<?php 2$apikey = 'API-KEY'; 3$channel_id = 'Youtube-ID'; 4$apiUrl = 'https://www.googleapis.com/youtube/v3/videos?id=' . $channel_id . '&key=' . $apikey . '&fields=items(snippet(title),contentDetails(duration),statistics(viewCount))' . '&part=snippet,contentDetails,statistics'; 5 6$json = file_get_contents($apiUrl); 7 8$json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN'); 9$json = json_decode($json); 10 11$viewCount = $json->items[0]->statistics->viewCount; //チャンネル内動画合計再生数 12$title = $json->items[0]->snippet->title; //チャンネル登録者数 13$durationData = $json->items[0]->contentDetails->duration; //チャンネル登録者数 14$duration = str_replace('PT', '', str_replace('H', ':', str_replace('M', ':', str_replace('S', '', $durationData)))); 15?> 16 17 18<p> <?php echo $viewCount; ?> </p> 19<p> <?php echo $title; ?> </p> 20<p> <?php echo $duration; ?> </p> 21
試したこと
下記サイトを参考にしたがうまく行きませんでした。
https://pikodon.com/note/solution/api-cache/#:~:text=Instagram%20Graph%20API%E3%81%AF1,%E5%BF%85%E8%A6%81%E3%81%A0%E3%81%A3%E3%81%9F%E3%82%8A%E3%81%97%E3%81%BE%E3%81%99%E3%80%82
補足情報(FW/ツールのバージョンなど)
WordPressサイトに実装します。

あなたの回答
tips
プレビュー