LoginSignup
2
2

More than 5 years have passed since last update.

GoogleのAPIでサーバ時間がズレていたことで正しく動かなかったよ、という話

Last updated at Posted at 2017-08-23

この記事は?

  • Google DriveのAPIを使って定常的に値の操作をしていたが、ある日突然、動かなくなっていた。
  • 話のオチとしては、サーバの時刻ズレによって発生したエラーだった。
  • あまり同じような記事をみなかったので情報共有と備忘録までに。

事の発端

あれ?動いてない?

とあるスクリプトを作り、
1. Google Drive API でファイルの一覧を取得し
2. そのなかから目的のSpreadSheetのIDを取得する
3. 取得したIDを元にGoogle Sheets API で表の中身を取得する
ということを実行していたのだが、ある日、動かなくなった。

エラーが出ていた

次のエラーが出ていた。

oauth2client.client.HttpAccessTokenRefreshError: 
invalid_grant: Invalid JWT: Token must be a short-lived token and in a reasonable timeframe

結論

サーバ時刻が現在時刻と大幅にズレている場合に発生するエラー。
具体的には5分のズレが発生するとエラーとなるらしい。

参考:Stackoverflow

caused in my case by a poor synchronisation of the computer's clock 
where the code was executed that had a lag of 5 minutes
 (due to a faulty battery for the internal clock).

そういえば

私の環境は今回はMacBook上にVirtualBoxでCentOSを動かして、そこでcronでスクリプト実行していたのですが、
この日の前日はうっかりMacBookを閉じ、VMがペンディング状態にしてしまったな…ということで
なんとなく当たりがついていたので気がつくことができました。
chronyは起動していたのですが、時刻同期が追いついていなかったようです。


以上

2
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
2
2