LoginSignup
7
2

More than 5 years have passed since last update.

Node.jsを利用してGoogle APIsでAnalyticsのv4を使うとanalyticsreportingがnot a function言われる時の対応

Last updated at Posted at 2018-05-15

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();

に変更すれば動いた・・・・。

7
2
1

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