すべてのページロードで以下のコードを実行する必要がないように、単純なifステートメントを試しましたが、dropbox_authStatusが1であると表示されますが、withの2番目の部分dropbox_authStatus === 1
はトリガーされalert("authStatus: "+dropbox_authStatus);
ません。コードの何が問題になっていますか?
$('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ライブラリに属しています:https ://github.com/dropbox/dropbox-js/blob/master/doc/getting_started.md