enyo.kind({ name: "App", components: [ {kind: "Button", content: "Authorize", ontap: "authAction"}, {name: "listInput", kind: "Input", value: "public"}, {name: "listButton", kind: "Button", content: "Go to Box - After you come back tap 'Get Token'", ontap: "listAction", disabled: true}, {name: "TokenButton", kind: "Button", content: "Get Token", ontap: "tokenAction", disabled: true}, {name: "See", kind: "Button", content: "See Info", ontap: "seeAction", disabled: true}, {name: "output", allowHtml: true} ], create: function() { this.inherited(arguments); this.apikey = <your api key>; //obtain from Box Platform Developers Page }, authAction: function() { this.$.output.addContent("Requesting tokens...<br/>"); var request = new enyo.Ajax({url: "https://www.box.com/api/1.0/rest?action=get_ticket&api_key=" + this.apikey,handleAs: "xml"});request.response(this, function(inSender, inGoodies) { console.log(inGoodies);xmlDoc = inGoodies.childNodes[0].childNodes[1].textContent;console.log(xmlDoc); if (xmlDoc) { this.auth_token = xmlDoc; console.log(this.auth_token); //this.auth_secret = inGoodies.secret; //this.$.output.addContent(xmlDoc); this.$.listButton.setDisabled(false); } else { this.$.output.addContent("failed" + inGoodies); } }) ;request.go(/*{user: "user", password: "password"}*/); }, listAction: function() { this.$.output.addContent("Requesting list...[" + this.$.listInput.getValue() + "]<br/>"); this.$.TokenButton.setDisabled(false); window.open("https://www.box.com/api/1.0/auth/" + this.auth_token); /*.go({token: this.auth_token, secret: this.auth_secret}) .response(this, function(inSender, inGoodies) { this.$.output.addContent(enyo.json.stringify(inGoodies) + "<hr/>"); }) ;*/ },tokenAction: function() { //https://www.box.com/api/1.0/rest?action=get_auth_token&api_key={your api key}&ticket={your ticket} new enyo.Ajax({ url: "https://www.box.com/api/1.0/rest?action=get_auth_token&api_key=" + this.apikey + "&ticket="+ this.auth_token, handleAs: "xml"}) .go(/*{token: this.auth_token, secret: this.auth_secret}*/) .response(this, function(inSender, inGoodies) { console.log(inGoodies);xmlDoc = inGoodies.childNodes[0].childNodes[1].textContent;console.log(xmlDoc); if (xmlDoc) { this.auth_token = xmlDoc; console.log(this.auth_token); new enyo.Ajax({ url: "https://www.box.com/api/2.0/folders/0", headers: {"Authorization": "BoxAuth api_key=" + this.apikey + "&auth_token="+ this.auth_token}, handleAs: "json"}) .go(/*{token: this.auth_token, secret: this.auth_secret}*/) .response(this, function(inSender, inGoodies) { this.$.output.addContent(enyo.json.stringify(inGoodies) + "<br/>"); }); this.$.See.setDisabled(false); } else { this.$.output.addContent("failed" + inGoodies); } }) ; }, seeAction: function() {new enyo.Ajax({ url: "https://www.box.com/api/2.0/folders/0", headers: {"Authorization": "BoxAuth api_key=" + this.apikey + "&auth_token="+ this.auth_token}, handleAs: "json"}) .go(/*{token: this.auth_token, secret: this.auth_secret}*/) .response(this, function(inSender, inGoodies) { this.$.output.addContent(enyo.json.stringify(inGoodies) + "<br/>"); }); }});
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
- Spam
- Abuse
0 • Off Topic Insightful •- Spam
- Abuse
0 • Off Topic Insightful •- Spam
- Abuse
0 • Off Topic Insightful •