我正在为我的 web 应用程序使用 Express,并检查会话中是否存在某些值,将用户重定向到 Instagram 登录页面。但在控制台中我不断收到 302 代码,并且浏览器不会重定向用户,这是我的代码。我正在使用 Ajax 发送我的请求。
function requireLogin (req, res, next) {
if (!req.token)
res.redirect('/auth');
else
next();
};
app.get('/auth',function(req,res,next){
res.redirect("https://api.instagram.com/oauth/authorize/?client_id="+client_id+"&redirect_uri="+redirect_uri+"&score=public_content+likes+comments+follower_list+relationships&response_type=code");
});
我检查了一下, app.get('/auth') 被调用,但似乎第二次重定向到 Instagram 没有执行任何操作。
问题是,如果您使用 Ajax,res.redirect 不会重定向用户。所以我将网址传递给客户端并使用window.location.replace(url);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)