node-googleanalytics icon indicating copy to clipboard operation
node-googleanalytics copied to clipboard

With a user and password:

Open amcritchie opened this issue 9 years ago • 14 comments

Hello, I am having an issue with logging in to google analytics via the username and password method. Below is my config, and my error. Have you experienced this error?

util = require('util'), config = { "user": GOOGLE_EMAIL, "password": GOOGLE_PASSWORD }, ga = new GA.GA(config);

{ [Error: BadAuthentication ] responseData: 'Error=BadAuthentication\nUrl=https://www.google.com/accounts/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbte89_uredV3sMhkh15QcN3AP4CvMXlwRzKMTPpbhpX8yX-LTUjbfo3UaIc5naE7KhhAa4C0hOlOIwCig-qpTelg-cuaE4EBJZWmMky_pWfa8CwsyorNhG2tbQonuxXHtC_dnazyvAMqICxncOM7SDu61Y3YFFZjwAQuNHZ_uUa2ss5nY0tjbG4fvXNb0KWssTNrVioDS12oBsaoQYiQGYIWSjRfFcjxzqgL8nzjz2rJiEQ1os\nInfo=WebLoginRequired\n' }

amcritchie avatar Apr 23 '15 20:04 amcritchie

Similar for me. I'm getting [Error: Invalid Credentials]

rogerdickey avatar Apr 24 '15 04:04 rogerdickey

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

ncb000gt avatar Apr 24 '15 19:04 ncb000gt

@rogerdickey @amcritchie do you have Two Factor Authentication enabled?

asadja avatar Apr 24 '15 19:04 asadja

Same problem here. I don't have two factor authentication enabled.

m1sta avatar May 19 '15 18:05 m1sta

I have got https://developers.google.com/identity/protocols/AuthForInstalledApps in response. Its happens as google is not supporting clientLogin now. Need to change it to support OAuth2.0.

rajeshujade avatar May 27 '15 05:05 rajeshujade

The latest version of Google's official googleapis package is actually quite easy to use, although the documentation sucks. Here's an example (using fibrous)...

 var authClient = new gapi.auth.JWT(serviceAccountEmail, serviceAccountKeyFile, null, scopes);
 var authResult = authClient.sync.authorize()
 var query = {
     'auth': authClient,
     'ids': 'ga:' + profileId,
     'start-date': '30daysAgo',
     'end-date': 'today',
     'metrics': 'ga:pageviews, ga:sessions'
 }
 var queryResult = gapi.analytics('v3').data.ga.sync.get(query)

You can get the serviceAccountKeyFile as a json file directly from the Google Console after you create a service account.

m1sta avatar May 27 '15 12:05 m1sta

Yeah. I used the same mechanism for my system.

rajeshujade avatar May 28 '15 04:05 rajeshujade

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

ncb000gt avatar May 28 '15 15:05 ncb000gt

Hi guys,

I was in the same boat - I found a semi-useful package here, however it was missing concurrency limiting which means it kept failing where Nicks library works, and had a few other issues that meant it wouldn't work for me, so I ended up writing one myself here:

https://github.com/jsguy/ga-api

npm install ga-api

Let me know if it works for you - @ncb000gt - I would have integrated it into your library, but the authentication method you use is deprecated, so I didn't see a good way to do so, though feel free to grab whatever I've written, if you find it useful.

jsguy avatar Jun 10 '15 06:06 jsguy

@jsguy Why use this over the Google-supported alternative?

m1sta avatar Jun 11 '15 12:06 m1sta

@m1sta This uses the google supported library - but more importantly, solves the issue of too many concurrent requests - @ncb000gt's library didn't have that issue, as the connection method does not impose the limits, so as soon as I started using the official google API, my reports started failing. I'm doing about 40 or so requests, depending on what data I get back from the first few, in order to calculate some values for custom reports.

jsguy avatar Jun 12 '15 05:06 jsguy

@m1sta I can't get your code to work - I just get undefined...

eldadts avatar Jun 22 '17 17:06 eldadts

throw err; ^

Error: Uncaught, unspecified "error" event. (https://developers.google.com/accounts/docs/AuthForInstalledApps )

ashjha1 avatar Apr 20 '18 11:04 ashjha1

https://developers.google.com/accounts/docs/AuthForInstalledApps

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.

 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 in this library will not work until the developer updates it to support the new login method as it hasn't been developed on in three years i think you may want to consider using the official Google apis node.js client library

@ncb000gt if your not going to develop on it anymore may i sugest you add a note that it wont work or take it down so developers dont waste there time. like here

LindaLawton avatar Apr 24 '18 06:04 LindaLawton