-1

すべてのページロードで以下のコードを実行する必要がないように、単純な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

4

2 に答える 2

0

元の質問に対するコメントから得られた回答

推測しているだけですが、ログが正しいように見えても条件が満たされていない場合はdropbox_authStatus、数値ではなく文字列である可能性があります。

于 2012-09-08T11:02:51.117 に答える
0

dropbox.js の最近のバージョンではinteractive: false、メソッドのオプションがサポートされていますclient.authenticate()。このパブリック API を使用して同じ目標を達成でき、ライブラリの更新時にコードが壊れることはありません。

コード スニペット: https://github.com/dropbox/dropbox-js/blob/master/doc/snippets.md#sign-into-dropbox-button

ドキュメントの認証: http://coffeedoc.info/github/dropbox/dropbox-js/master/classes/Dropbox/Client.html#authenticate-instance

于 2013-02-18T10:15:03.263 に答える