【问题标题】:Dropbox authentication with Phonegap使用 Phonegap 进行 Dropbox 身份验证
【发布时间】:2016-05-05 19:36:11
【问题描述】:

我的问题是,当我尝试使用 Phonegap 应用程序从 Dropbox 获取 access_token 时,出现以下错误:

不允许加载本地资源:file:///android_asset/www/index.html#access_token={MY_ACCESS_TOKEN}&token_type=bearer&state=%3CCSRF+token%3E&uid=130101032

document.addEventListener("deviceready", onDeviceReadyLoginDropbox, false);
    function onDeviceReadyLoginDropbox() {
         var url = document.URL, 
        shortUrl=url.substring(0,url.lastIndexOf("/"));

    console.log(cordova.InAppBrowser);

    var ref = cordova.InAppBrowser.open('https://www.dropbox.com/1/oauth2/authorize?client_id={APP_KEY}&response_type=token&redirect_uri='+shortUrl+'/index.html&state=%3CCSRF%20token%3E', "_blank");
    }

所以,一切正常,但重定向不是这样,这里的解决方法是什么?我读到使用 JS 你无法访问本地文件,那么当重定向不起作用时,我如何获得访问令牌?唯一的可能就是只使用 JS。

【问题讨论】:

    标签: javascript cordova dropbox dropbox-api


    【解决方案1】:

    您必须处理来自 cordova.InAppBrowser 的重定向事件。

    您可以在页面加载时添加他的事件处理程序。

    您必须检查登录是否成功(您可以在url中搜索“ACCESS_TOKEN”), 并从成功 url 中获取。

    代码如下:

        ref.addEventListener('loadstart', function(event) {
           // you have here url at event.url
    
           if(event.url.indexOf('success') > -1){
             // take token
    
    
           }
    
     });
    

    您可以找到所有活动here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多