Skip to content

Instantly share code, notes, and snippets.

@harushimo
Last active December 10, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harushimo/4365970 to your computer and use it in GitHub Desktop.
Save harushimo/4365970 to your computer and use it in GitHub Desktop.
sample
#!/usr/local/bin/node
//Writing a configuration file
var config = {
"secrets" : {
"clientId" : "GOZ5E3WU0KPGHAU4NDRBDNT2F2BVAP0SGCMZJAQAI4EOOGMT",
"clientSecret": "HLZJO1OEXMPKXVDO23Z4EE3WBHS2ZSBUBU4UWALW2ZSFEFNR",
"redirectUrl": "https://localhost:3000/callback"
}
,"foursquare" : {
"version" : "20121223"
}
}
//Calling the node's foursquare api
var foursquare = require("node-foursquare")(config);
//Creating the server on local machine
var express = require('express');
var app = express();
app.listen(3000);
//Login into the API
app.get('/login', function(request, response) {
request.writeHead(303, {"location": foursquare.getAuthClientRedirectUrl() });
request.end();
});
app.get('/callback', function(request, response) {
foursquare.getAccessToken({
code: request.query.code
}, function(error, accessToken) {
if (error) {
response.send("An error occured: " + error.message)
}
else {
console.log(accessToken)
}
});
});
Error Message:
TypeError: Object #<IncomingMessage> has no method 'writeHead'
at /Users/harI/app.js:23:15
at callbacks (/Users/harI/node_modules/express/lib/router/index.js:160:37)
at param (/Users/harI/node_modules/express/lib/router/index.js:134:11)
at pass (/Users/harI/node_modules/express/lib/router/index.js:141:5)
at Router._dispatch (/Users/harI/node_modules/express/lib/router/index.js:169:5)
at Object.router (/Users/harI/node_modules/express/lib/router/index.js:32:10)
at next (/Users/harI/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.expressInit [as handle] (/Users/harI/node_modules/express/lib/middleware.js:31:5)
at next (/Users/harI/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.query [as handle] (/Users/harI/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment