Search code examples
node.jsexpressfoursquare

Foursquare Check-in Reply


I am trying to Connect my application to foursquare and I want to display a message when a user checks in to certain places. I am trying to use their real time api https://developer.foursquare.com/overview/realtime

Everything works fine until the very end, ( when I have to send a reply post request https://developer.foursquare.com/docs/checkins/reply) I am using express and node.js. Here is what my post request looks like.

app.post('/handlepush', function(req, res) {
 var checkin_id =req.param('checkin');
 console.log(checkin_id);
 var obj = JSON.parse(checkin_id);
 var id = obj.id;

res.end('It worked!');

var token = "********************************";

var post_data = querystring.stringify({text : "awesome"});
var options = {
    host: 'api.foursquare.com',
    path: '/v2/checkins/' + id + '/reply?oauth_token=' + token,
    port: 443,
    method: 'POST'
};

var req2 = https.request(options, function(res2) {
    res2.setEncoding('utf8');
    res2.on('data', function (chunk) {
        console.log('BODY: ' + chunk);
  });

req2.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});

});
req2.write(post_data);
req2.end();



});

this is the error I get, for some reason I am not able to add parameters for my post: BODY: {"meta":{"code":400,"errorType":"other","errorDetail":"Must provide parameter text"},"response":{}}


Solution

  • You need to actually send your request. See: How to make an HTTP POST request in node.js?

    var req2 = http.request(options, function(res2) {
        res2.setEncoding('utf8');
        res2.on('data', function (chunk) {
            console.log('BODY: ' + chunk);
        });
    });
    req2.end();