2

我正在尝试在我的 Web 应用程序中迁移到 dropbox-api v2。目前我已经实现了打开弹出窗口,用户连接到他/她的保管箱并获得令牌。在后面的步骤中,我使用它来访问用户在 Dropbox.chooser 中选择的文件。

但我很难找到解决方案。我有所有迁移文档的链接 Dropbox 有,但没有任何关于 client.authenticate() 和 Dropbox.AuthDriver.Popup() 的等价物的消息?

4

1 回答 1

5

普通的Dropbox!!!我刚刚在 GitHub 上发现了这个关于 dropbox-sdk-js 的问题,以及他们在 V2 中没有这个功能的答案 :( 真的很令人失望,我需要自己实现所有员工:

https://github.com/dropbox/dropbox-sdk-js/issues/73#issuecomment-247382634

更新

我已经实施了我的解决方案,如果有人需要,我想分享一下。

要打开一个弹出窗口,我使用以下代码:

window.open(dropbox.getAuthenticationUrl("MY REDIRECT URL"), 'DropboxAuthPopup', 'dialog=yes,dependent=yes,scrollbars=yes,location=yes')
        
window.addEventListener('message',function(e) {
   if (window.location.origin !== e.origin) {
       // Throw error
   } else {
       // e.data Is what was sent from redirectUrl
       // e.data.access_token is the token I needed from dropbox
   }
},false);

然后在我指定要重定向的保管箱的页面上,我输入:

window.addEventListener('load', function() {
    var message = parseQueryString(window.location.hash)
    window.location.hash = '';
    
    opener = window.opener
    if (window.parent != window.top) {
        opener =  opener || window.parent
    }
    
    opener.postMessage(message, window.location.origin);
    window.close();

})

可以从dropbox-sdk-js 示例中找到 parseQueryString 的示例

于 2016-12-09T18:35:49.380 回答