javascript - JS require in QML -


i using dbox library in qml app (sources available @ github). in qml file import dbox library following code:

import "./dbox-master/lib/dbox.js" dbox 

then use in way:

var app   = dbox.app({ "app_key": root.appkey, "app_secret": root.appsecret }) 

however, in dbox.js there're series of require statements, @ top of file:

define(['require', 'request', 'querystring', 'path'], function (require) {     var request = require('request');     var qs = require('querystring');     var path = require('path');     var helpers_ = require("./helpers") //    var request = require('request'); }); //var request = require("request") //var qs      = require("querystring") //var path    = require("path") //require(['request'], function (foo) { //    console.log('request loaded') //});  exports.app = function(config){   var root   = config.root  || "sandbox"   var helpers = helpers_(config)    return {     root: root,      requesttoken: function(cb){       var signature = helpers.sign({})       var body = qs.stringify(signature)       var args = {         "method": "post",         "headers": {            "content-type": "application/x-www-form-urlencoded",           "content-length": body.length         },         "url": "https://api.dropbox.com/1/oauth/request_token",         "body": body       }       return request(args, function(e, r, b){         var obj = qs.parse(b)         obj.authorize_url = "https://www.dropbox.com/1/oauth/authorize?oauth_token=" + obj.oauth_token         cb(e ? null : r.statuscode, obj)       })     },... 

as see, i've changed code dbox.js work require not defined. how use require.js properly?

update. found out, problem in host environment. qml global space constant. node.js requires objects present in space (e.g. iself) , importing global space. there project on github glueing node.js , qml not finished yet. propose solution: make c++ plugin run script in js. script run in node.js environment communicate dropbox account information quick-based application.

what best approach use web api? dropbox in case.

it depends.

since need list files , download file, best choice use dropbox api manually.

i used oauth2 authorize application, token flaw, because fast.

webview app. built-in browser. once redirect_uri set webview url property value means authorization passed. access token returned redirection.

note. redirect_uri must equal redirect_uri set in application appconsole in app. dropbox account.

result: did not use 3d party dropbox js libraries, faster send requests manually.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -