Permalink
Browse files

Trying to get examples to work - but so far unable to pull a feed wit…

…h success
  • Loading branch information...
1 parent 68cf268 commit 232e12cb44fe3780dec77b2c5b0fe1b9901313f9 @jimib committed Feb 6, 2013
Showing with 103 additions and 21 deletions.
  1. +57 −0 examples/example-auth.js
  2. +42 −0 examples/example-get-contacts.js
  3. +0 −15 examples/index.js
  4. +1 −3 index.js
  5. +3 −3 lib/api.js
View
@@ -0,0 +1,57 @@
+var gAPI = require('../index').API;
+var fs = require("fs");
+//put your authentication stuff in 'auth.conf'
+var auth = fs.readFile("./auth.conf", function(err, data){
+ if(data){
+ try{
+ console.log(data.toString());
+ data = JSON.parse(data.toString());
+ }catch(error){
+ err = error;
+ }
+ }
+
+ if(err){
+ console.log("Unable to load config file 'examples/auth.conf'", err);
+ }else{
+ var express = require('express');
+ var app = express();
+ var port = 4000;
+
+ app.get('/', function(req, res){
+ res.send('hello');
+ });
+
+ app.get('/oauth2callback', function(req, res){
+ if(!req.query.code){
+ //Redirect the user to Authentication From
+ api.oauth.getGoogleAuthorizeTokenURL( ['https://www.googleapis.com/auth/contacts'], function(err, redirecUrl) {
+ if(err) return res.send(500,err);
+ return res.redirect(redirecUrl);
+ });
+
+ }else{
+ //Get access_token from the code
+ api.oauth.getGoogleAccessToken(req.query, function(err, access_token, refresh_token) {
+ if(err) return res.send(500,err);
+
+ console.log("access_token", access_token);
+ console.log("refresh_token", refresh_token);
+
+ return res.redirect('/');
+ });
+ }
+ });
+
+ console.log("gAPI", gAPI);
+
+ var api = new gAPI(
+ data.consumer_key,
+ data.consumer_secret,
+ 'http://localhost:'+port+'/oauth2callback');
+
+ app.listen(port);
+ }
+
+})
+
@@ -0,0 +1,42 @@
+var gAPI = require('../index').API;
+var fs = require("fs");
+//put your authentication stuff in 'auth.conf'
+var auth = fs.readFile("./auth.conf", function(err, data){
+ if(data){
+ try{
+ console.log(data.toString());
+ data = JSON.parse(data.toString());
+ }catch(error){
+ err = error;
+ }
+ }
+
+ if(err){
+ console.log("Unable to load config file 'examples/auth.conf'", err);
+ }else{
+ var express = require('express');
+ var app = express();
+ var port = 4000;
+
+ app.get('/', function(req, res){
+ //get my list of contacts
+ var email = encodeURIComponent("jimi.bailey@gmail.com");
+ var urlRequest = "https://www.google.com/m8/feeds/contacts/"+email+"/full";
+
+ api.oauth._request("GET", urlRequest, {"GData-Version" : "3.0"}, "", data.access_token, function(result){
+ res.send(result.data);
+ });
+ });
+
+ console.log("gAPI", gAPI);
+
+ var api = new gAPI(
+ data.consumer_key,
+ data.consumer_secret,
+ 'http://localhost:'+port+'/oauth2callback');
+
+ app.listen(port);
+ }
+
+})
+
View
@@ -1,15 +0,0 @@
-var gOAuth = require('../index');
-
-var express = require('express');
-var app = express();
-var port = 4000;
-
-app.get('/', function(req, res){
- res.send('hello world');
-});
-
-var gOAuth = new OAuth.OAuth2(
- ,
- 'http://localhost:'+port+'/authentication');
-
-app.listen(port);
View
@@ -1,3 +1 @@
-module.exports = function(consumer_key, consumer_secret, callback_uri){
- return new require("./lib/api")(consumer_key, consumer_secret, callback_uri);
-}
+module.exports.API = require("./lib/api");
View
@@ -1,10 +1,10 @@
-var gOAuth = require("google-oauth"),
- request = require("./request");
+var OAuth = require("google-oauth"),
+ Request = require("./request");
var API = module.exports = function(consumer_key, consumer_secret, callback_uri){
var self = this;
- self.oauth = new gOAuth(consumer_key, consumer_secret, callback_uri);
+ self.oauth = new OAuth.OAuth2(consumer_key, consumer_secret, callback_uri);
//generate the parts to the
self.request = new Request(self.oauth);

0 comments on commit 232e12c

Please sign in to comment.