如何从NODE JS访问Google Analytics

时间:2022-05-22 14:28:37

I have tried with gooleanalytics

我尝试过gooleanalytics

var GA = require('googleanalytics'),
    util = require('util'),
    config = {
        "user": "myusername",
        "password": "mypassword"
    },
    ga = new GA.GA(config);

ga.login(function(err, token) {
    var options = {
        'ids': 'ga:<profileid>',
        'start-date': '2010-09-01',
        'end-date': '2010-09-30',
        'dimensions': 'ga:pagePath',
        'metrics': 'ga:pageviews',
        'sort': '-ga:pagePath'
    };

    ga.get(options, function(err, entries) {
       util.debug(JSON.stringify(entries));
    });
});

But getting error

但是得到错误

events.js:165 throw err; ^

events.js:165 throw err; ^

Error: Uncaught, unspecified "error" event. (https://developers.google.com/accounts/docs/AuthForInstalledApps ) at GA.emit (events.js:163:17)

错误:未捕获,未指定的“错误”事件。 (https://developers.google.com/accounts/docs/AuthForInstalledApps)在GA.emit(events.js:163:17)

1 个解决方案

#1


2  

Important: ClientLogin has been officially deprecated since April 20, 2012 and is now no longer available. Requests to ClientLogin will fail with a HTTP 404 response. We encourage you to migrate to OAuth 2.0 as soon as possible.

重要提示:ClientLogin自2012年4月20日起正式弃用,现已不再提供。对ClientLogin的请求将因HTTP 404响应而失败。我们建议您尽快迁移到OAuth 2.0。

 config = {
        "user": "myusername",
        "password": "mypassword"
    },

You are trying to authenticate to Google using login and password. This is called client login and was shut down in 2015 for all APIs. You will need to authenticate to google using either Oauth2 or a service account. The code and the library you are using will not work until the developer updates it to support the new login method as it hasnt been developed on in three years i think you may want to consider using the official Google apis node.js client library example analyticsReporting/batchGet.js

您正尝试使用登录名和密码向Google进行身份验证。这称为客户端登录,并于2015年针对所有API关闭。您需要使用Oauth2或服务帐户对Google进行身份验证。您正在使用的代码和库将无法工作,直到开发人员更新它以支持新的登录方法,因为它在三年内未开发,我认为您可能需要考虑使用官方Google apis node.js客户端库示例analyticsReporting /batchGet.js

Update

更新

With a user and password I tracked down the github project for this and it looks like the developer knows about the issue but chooses not to update the project.

使用用户和密码我跟踪了github项目,看起来开发人员知道这个问题,但选择不更新项目。

ncb000gt commented on Apr 24, 2015

ncb000gt于2015年4月24日发表评论

No idea sorry. I haven't used this module in quite a long time so I'm not really sure what the deal is.

不知道抱歉。我很长时间没有使用过这个模块,所以我不确定这笔交易是什么。

Which was around the exact date that it was shut down. Meaning he was informed as soon as it happened.

这是关闭它的确切日期。意味着一旦发生,他就会被告知。

ncb000gt commented on May 28, 2015

ncb000gt于2015年5月28日发表评论

I'd absolutely entertain a PR for this if anyone wants to take a stab at it. Otherwise, an official api may be better.

如果有人想要刺破它,我绝对会为此招待公关。否则,官方api可能会更好。

It appears the author is looking for assistance if someone wants to fix it.

如果有人想要修复它,作者似乎正在寻求帮助。

#1


2  

Important: ClientLogin has been officially deprecated since April 20, 2012 and is now no longer available. Requests to ClientLogin will fail with a HTTP 404 response. We encourage you to migrate to OAuth 2.0 as soon as possible.

重要提示:ClientLogin自2012年4月20日起正式弃用,现已不再提供。对ClientLogin的请求将因HTTP 404响应而失败。我们建议您尽快迁移到OAuth 2.0。

 config = {
        "user": "myusername",
        "password": "mypassword"
    },

You are trying to authenticate to Google using login and password. This is called client login and was shut down in 2015 for all APIs. You will need to authenticate to google using either Oauth2 or a service account. The code and the library you are using will not work until the developer updates it to support the new login method as it hasnt been developed on in three years i think you may want to consider using the official Google apis node.js client library example analyticsReporting/batchGet.js

您正尝试使用登录名和密码向Google进行身份验证。这称为客户端登录,并于2015年针对所有API关闭。您需要使用Oauth2或服务帐户对Google进行身份验证。您正在使用的代码和库将无法工作,直到开发人员更新它以支持新的登录方法,因为它在三年内未开发,我认为您可能需要考虑使用官方Google apis node.js客户端库示例analyticsReporting /batchGet.js

Update

更新

With a user and password I tracked down the github project for this and it looks like the developer knows about the issue but chooses not to update the project.

使用用户和密码我跟踪了github项目,看起来开发人员知道这个问题,但选择不更新项目。

ncb000gt commented on Apr 24, 2015

ncb000gt于2015年4月24日发表评论

No idea sorry. I haven't used this module in quite a long time so I'm not really sure what the deal is.

不知道抱歉。我很长时间没有使用过这个模块,所以我不确定这笔交易是什么。

Which was around the exact date that it was shut down. Meaning he was informed as soon as it happened.

这是关闭它的确切日期。意味着一旦发生,他就会被告知。

ncb000gt commented on May 28, 2015

ncb000gt于2015年5月28日发表评论

I'd absolutely entertain a PR for this if anyone wants to take a stab at it. Otherwise, an official api may be better.

如果有人想要刺破它,我绝对会为此招待公关。否则,官方api可能会更好。

It appears the author is looking for assistance if someone wants to fix it.

如果有人想要修复它,作者似乎正在寻求帮助。