2013-03-07 15 views
0

我想将我的应用程序连接到foursquare,并且我想在用户登录到某些地方时显示一条消息。我试图使用他们的实时api https://developer.foursquare.com/overview/realtimeFoursquare签入回复

一切工作正常,直到最后,(当我必须发送回复帖子请求https://developer.foursquare.com/docs/checkins/reply)我使用express和node.js.这是我的发布请求的样子。

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(); 



}); 

这是我的错误,由于某种原因,我不能添加参数为我的帖子: BODY:{“元”:{“代码”:400,“错误类型”:“其他” ,“errorDetail”:“必须提供参数文本”},“response”:{}}

+0

任何人都可以提供一个示例API调用,如果我的问题? – 2013-03-07 05:16:16

回答

1

您需要实际发送您的请求。见: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(); 
+0

所以我改变了一下,现在它几乎工作..但我只需要找出一种方法来添加参数。 – 2013-03-07 17:47:13

+1

“text”应该是查询字符串中的一个参数: 'path:'/ v2/checkins /'+ id +'/ reply?oauth_token ='+ token +'&text = Text%20to%20show%20user,' – octopi 2013-03-07 18:33:56

+0

有效的工作!但我有点困惑,我认为后期参数不应该在网址..? – 2013-03-07 20:15:36

相关问题