Google AnalyticsからGoogle APIsを経由して利用する場合にちょっとだけハマったのでメモ
Node.jsでGoogle AnalyticsのPV数を取得
Google APIs Analytics Samples
上記のものを参考にコードを書いても analyticsreporting の箇所で
TypeError: google.analyticsreporting is not a function
とエラー吐いて終わります・・。
他のサンプルも同様の書き方になってるものが多く、なんか僕だけ指から電波出して動かないのか?と不信になる程調べても原因が見つかりません。
で、調べてみると以下のリリース情報を見てるとどうやら呼び出し方が26.0.0から変わってる模様。
https://github.com/google/google-api-nodejs-client/releases
before
var {google} = require('googleapis');
を
after
const {GoogleApis} = require('googleapis');
const google = new GoogleApis();
に変更すれば動いた・・・・。