node-googleanalytics
node-googleanalytics copied to clipboard
With a user and password:
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' }
Similar for me. I'm getting [Error: Invalid Credentials]
No idea sorry. I haven't used this module in quite a long time so I'm not really sure what the deal is.
@rogerdickey @amcritchie do you have Two Factor Authentication enabled?
Same problem here. I don't have two factor authentication enabled.
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.
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.
Yeah. I used the same mechanism for my system.
I'd absolutely entertain a PR for this if anyone wants to take a stab at it. Otherwise, an official api may be better.
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 Why use this over the Google-supported alternative?
@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.
@m1sta I can't get your code to work - I just get undefined...
throw err; ^
Error: Uncaught, unspecified "error" event. (https://developers.google.com/accounts/docs/AuthForInstalledApps )
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