LoginSignup
1
2

More than 5 years have passed since last update.

Google Feed API 廃止への対応

Posted at

経緯

2015年12月2日頃にGoogle Feed APIが廃止されました。
僕はこれはGoogleの「日本の祝日」カレンダーの情報を取るためにこのAPIを使っていました。
そのため祝日を取得する方法を紹介しているブログの内容は使えなくなってしまいました。
例外なく以業務で前僕が書いた某スクリプトも廃止の影響を受けてしまったので対応しました。
本稿はこの問題にどう対応したのかについてのメモです。

修正パッチ

まず先に修正パッチを示します。

変更前

$start_time = date("Y-m-d");
$calendar_id = urlencode('japanese__ja@holiday.calendar.google.com');
$url = "https://www.google.com/calendar/feeds/{$calendar_id}/public/basic?start-min={$start_time}&max-results=30&alt=json";
$content = file_get_contents($url);

変更後

require_once 'class.iCalReader.php';
$a = new ical('https://calendar.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics');
$a = $a->events();

対策

取得元を iCal に変更する

  1. Googleカレンダーより、「日本の祝日」のカレンダー設定画面を開き、「カレンダーのアドレス」のうち「iCal」をクリックします
  2. ポップアップを見るとiCalのURLが判明します

iCalをPHPで読み込むには

MartinThoma/ics-parserを使いました。require_once()で十分ですね。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2