Permalink
Browse files

Merge pull request #22 from bsphere/master

Bug fixes for access token flow
  • Loading branch information...
2 parents 01449ae + 8a7f859 commit 51b353c0c8499789691296326678006230b48f01 @ncb000gt committed Feb 1, 2013
Showing with 21 additions and 6 deletions.
  1. +9 −2 README.md
  2. +9 −2 lib/ga.js
  3. +3 −2 package.json
View
@@ -37,12 +37,12 @@ With a user and password:
});
});
-If you have already gotten permission from a user, you can simply use the oAuth refresh token you have:
+If you have already gotten permission from a user, you can simply use the oAuth access token you have:
var GA = require('googleanalytics'),
util = require('util'),
config = {
- "token": "Auth=XXXXXXXXXXX"
+ "token": "XXXXXXXXXXXX"
},
ga = new GA.GA(config);
@@ -59,6 +59,9 @@ If you have already gotten permission from a user, you can simply use the oAuth
util.debug(JSON.stringify(entries));
});
+You can specify the type of token by setting 'tokenType', default is 'Bearer'.
+
+See [node-gapitoken][gapi] for easy service account Server to Server authorization flow.
Rudamentary API
============
@@ -91,6 +94,7 @@ Contributors
* [Brian Zeligson][beezee] - Updates for a more recent version of node. Also makes use of better selectors.
+* [Gal Ben-Haim][bsphere] - Bug fixes for access token flow.
License
============
@@ -99,3 +103,6 @@ see license file
[beezee]:https://github.com/beezee
+[bsphere]:https://github.com/bsphere
+
+[gapi]:https://github.com/bsphere/node-gapitoken
View
@@ -16,14 +16,21 @@ function GA(config) {
if (config) {
if ('user' in config) {
this.user = config.user;
+ this.tokenType = 'GoogleLogin';
}
if ('password' in config) {
this.password = config.password;
}
+ this.token = ('token' in config) ? config.token : null;
+ if ('token' in config) {
+ this.tokenType = config.tokenType || 'Bearer';
+ }
+ if ('token' in config && ('user' in config || 'password' in config)) {
+ throw Error("Invalid config.");
+ }
} else {
throw Error("No config given.");
}
- this.token = ('token' in config) ? config.token : null;
};
inherits(GA, emitter);
@@ -102,7 +109,7 @@ GA.prototype.get = function(options, cb) {
path: data_url,
method: 'GET',
headers: {
- Authorization:"GoogleLogin "+this.token,
+ Authorization: this.tokenType + " " + this.token,
"GData-Version": 2
}
};
View
@@ -2,11 +2,12 @@
"name": "googleanalytics",
"main": "./lib/ga",
"description": "Google Analytics library.",
- "version": "0.3.0",
+ "version": "0.3.2",
"author": "Nick Campbell (http://github.com/ncb000gt)",
"contributors": [
{ "name": "Brian Zeligson (http://github.com/beezee)", "email": "brian.zeligson@gmail.com" },
- { "name": "Mike Schierberl (http://github.com/mschierberl)", "email": "mike@schierberl.com" }
+ { "name": "Mike Schierberl (http://github.com/mschierberl)", "email": "mike@schierberl.com" },
+ { "name": "Gal Ben-Haim (http://github.com/bsphere", "email": "gbenhaim@gmail.com"}
],
"engines": { "node": ">= 0.4.0" },
"repository": {

0 comments on commit 51b353c

Please sign in to comment.