Answer the question
In order to leave comments, you need to log in
Why doesn't the res.send function work?
app.get('/watch',function(req, res) {
var id = req.query.rid,
code = req.query.codes;
getTokenFromVK(code,function(acc){
console.log("access_token : "+acc);
access_token = acc;
console.log('resc '+res);
if(req.query.btn=="create"){
roomid = createRoom('Test');
console.log("roomid="+roomid);
res.send('/watch/'+roomid);
}
else if (req.query.btn=="join") {
res.send('/watch/'+id);
}
});
});
if(req.query.btn=="create"){
roomid = createRoom('Test');
console.log("roomid="+roomid);
res.send('/watch/'+roomid);
}
else if (req.query.btn=="join") {
res.send('/watch/'+id);
}
for the callback function, then everything works fine. What could be the problem ? function getTokenFromVK(codes, callback) {
request.get('https://oauth.vk.com/access_token?client_id=5124623&client_secret=ETFO5R3J8xgnu4CjpKt5&redirect_uri=localhost:3000/home&code='+codes,function (err,res,body){
_access_token = body.split(":")[1].split(",")[0].split("\"")[1];
callback(access_token);
});
}
Answer the question
In order to leave comments, you need to log in
The point here is not res.send, but the fact that inside callback - req.query.btn is invisible (that is, scope does not allow it to be there) therefore none of your if(req.query.btn=="create") or else if (req.query.btn=="join") doesn't work... an
easy way to assign req.query.btn to var btnCheck and therefore check it inside the callback...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question