Javascript Dropbox oauth athentication的IF语句的第二部分是';t触发
我尝试了一个简单的if语句,以避免在每次页面加载时都必须运行下面的代码,但是第二部分的Javascript Dropbox oauth athentication的IF语句的第二部分是';t触发,javascript,if-statement,dropbox,Javascript,If Statement,Dropbox,我尝试了一个简单的if语句,以避免在每次页面加载时都必须运行下面的代码,但是第二部分的dropbox\u authStatus===1没有被触发,尽管alert(“authStatus:+dropbox\u authStatus”)告诉我dropbox\u authStatus为1。我的代码怎么了 $('document').ready(function() { dropbox_authStatus = localStorage.getItem('dropbox_authstatus'); a
dropbox\u authStatus===1
没有被触发,尽管alert(“authStatus:+dropbox\u authStatus”)代码>告诉我dropbox\u authStatus为1。我的代码怎么了
$('document').ready(function() {
dropbox_authStatus = localStorage.getItem('dropbox_authstatus');
alert("authstatus: "+dropbox_authStatus);
if(!dropbox_authStatus) {
localStorage.setItem('dropbox_authstatus',1);
//initialization
var client = new Dropbox.Client({
key: "hm4c58qp6rpysot", secret: "w7cdx6o8p2hyubj"
});
alert("initialized");
//preset driver to the dropbox page
client.authDriver(new Dropbox.Drivers.Redirect());
//authentication
client.authenticate(function(error, client) {
if (error) {
return showError(error); // Something went wrong.
}
});
} else if (dropbox_authStatus === 1) {
localStorage.setItem('dropbox_authstatus',2);
//initialization
var client = new Dropbox.Client({
key: "hm4c58qp6rpysot", secret: "w7cdx6o8p2hyubj"
});
alert("continued");
//preset driver to the dropbox page
client.authDriver(new Dropbox.Drivers.Redirect());
//authentication
client.authenticate(function(error, client) {
if (error) {
return showError(error); // Something went wrong.
}
client.getUserInfo(function(error, userInfo) {
if (error) {
return showError(error); // Something went wrong.
}
alert("hello: "+userInfo.name);
});
});
//Save Dropbox credentials
localStorage.setItem('dropbox_auth', JSON.stringify(client.credentials()));
alert("credentials saved:"+JSON.stringify(client.credentials()));
}
});
提前谢谢!if语句中的代码主要属于github上托管的dropbox.js库:答案来自对原始问题的评论
我只是猜测,但是如果日志似乎正确,但不满足条件,则可能dropbox\u authStatus
是一个字符串而不是一个数字。dropbox.js的最新版本支持client.authenticate()
方法上的交互式:false
选项。您可以使用此公共API来实现相同的目标,并且您的代码不会在库更新时中断
代码段:
验证文档:也许dropbox\u authStatus
是一个字符串,而不是一个数字?就是这样!我用对感知过程的描述代替了数字,它起作用了。谢谢你的快速回答:)