I used the following code (taken from PDF.CO) to merge multiple pdf files in Google Drive:
/**
* Initial Declaration and References
*/
// Get the active spreadsheet and the active sheet
ss = SpreadsheetApp.getActiveSpreadsheet();
ssid = ss.getId();
// Look in the same folder the sheet exists in. For example, if this template is in
// My Drive, it will return all of the files in My Drive.
var ssparents = DriveApp.getFileById(ssid).getParents();
// Loop through all the files and add the values to the spreadsheet.
var folder = ssparents.next();
/**
* Add PDF.co Menus in Google Spreadsheet
*/
function onOpen() {
var menuItems = [
{name: 'Get All PDF From Current Folder', functionName: 'getPDFFilesFromCurFolder'},
{name: 'Merge PDF URLs Listed In Cell', functionName: 'mergePDFDocuments'}
];
ss.addMenu('PDF.co', menuItems);
}
/**
* Get all PDF files from current folder
*/
function getPDFFilesFromCurFolder() {
var files = folder.getFiles();
var pdfUrlCell = ss.getRange("A4");
var allFileUrls = [];
while (files.hasNext()) {
var file = files.next();
var fileName = file.getName();
if(fileName.endsWith(".pdf")){
// Make File Pulblic accessible with URL so that it can be accessible with external API
var resource = {role: "reader", type: "anyone"};
Drive.Permissions.insert(resource, file.getId());
// Add Url
allFileUrls.push(file.getDownloadUrl());
}
pdfUrlCell.setValue(allFileUrls.join(","));
}
}
function getPDFcoApiKey(){
// Get PDF.co API Key Cell
let pdfCoAPIKeyCell = ss.getRange("B1");
return pdfCoAPIKeyCell.getValue();
}
/**
* Function which merges documents using PDF.co
*/
function mergePDFDocuments() {
// Get Cells for Input/Output
let pdfUrlCell = ss.getRange("A4");
let resultUrlCell = ss.getRange("B4");
let pdfUrl = pdfUrlCell.getValue();
// Prepare Payload
const data = {
"async": true, // As we have large volumn of PDF files, Enabling async mode
"name": "result",
"url": pdfUrl
};
// Prepare Request Options
const options = {
'method' : 'post',
'contentType': 'application/json',
'headers': {
"x-api-key": getPDFcoApiKey()
},
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(data)
};
// Get Response
// https://developers.google.com/apps-script/reference/url-fetch
const resp = UrlFetchApp.fetch('https://api.pdf.co/v1/pdf/merge', options);
// Response Json
const respJson = JSON.parse(resp.getContentText());
if(respJson.error){
console.error(respJson.message);
}
else{
// Job Success Callback
const successCallbackFn = function(){
// Upload file to Google Drive
uploadFile(respJson.url);
// Update Cell with result URL
resultUrlCell.setValue(respJson.url);
}
// Check PDF.co Job Status
checkPDFcoJobStatus(respJson.jobId, successCallbackFn);
}
}
/**
* Checks PDF.co Job Status
*/
function checkPDFcoJobStatus(jobId, successCallbackFn){
// Prepare Payload
const data = {
"jobid": jobId
};
// Prepare Request Options
const options = {
'method' : 'post',
'contentType': 'application/json',
'headers': {
"x-api-key": getPDFcoApiKey()
},
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(data)
};
// Get Response
// https://developers.google.com/apps-script/reference/url-fetch
const resp = UrlFetchApp.fetch('https://api.pdf.co/v1/job/check', options);
// Response Json
const respJson = JSON.parse(resp.getContentText());
if(respJson.status === "working"){
// Pause for 3 seconds
Utilities.sleep(3 * 1000);
// And check Job again
checkPDFcoJobStatus(jobId, successCallbackFn);
}
else if(respJson.status == "success"){
// Invoke Success Callback Function
successCallbackFn();
}
else {
console.error(`Job Failed with status ${respJson.status}`);
}
}
/**
* Save file URL to specific location
*/
function uploadFile(fileUrl) {
var fileContent = UrlFetchApp.fetch(fileUrl).getBlob();
folder.createFile(fileContent);
}
It runs perfectly the first time, but then gives an error:
Exception: Request failed for https://api.pdf.co returned code 402. Truncated server response: {"status":"error","errorCode":402,"error":true,"message":"Not enough credits, subscription expired or metered use is not allowed. Please review cre... (use muteHttpExceptions option to examine full response).
been working with visual studio code and I am trying to use the built debugger. I have found examples and have tried to set it up. I have successfully got the gulp serve task setup and it runs correctly with the command
⇧⌘B
not the actual play button in the debugger tab. The examples I have found for debugging with the chrome extension does not include grunt or gulp automated tasks. Is it possible to use the gulp tasks and the debugger?
launch.json
{
"version": "0.2.0",
"configurations": [
{
"request": "launch",
// Name of configuration; appears in the launch configuration drop down menu.
"name": "node gulp.js ..",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "${workspaceRoot}./node_modules/gulp/bin/gulp.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": "${workspaceRoot}.",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": "${execPath}",
// Optional arguments passed to the runtime executable.
"runtimeArgs": [],
// Environment variables passed to the program.
"env": {},
// Use JavaScript source maps (if they exist).
"sourceMaps": false,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": "${workspaceRoot}out"
}
]
}
tasks.json
{
// See http://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "serve",
"args": [],
"isBuildCommand": true,
"isWatching": true,
"problemMatcher": [
"$lessCompile",
"$tsc",
"$jshint"
]
}
]
}
gulp.config.js
module.exports = function($, usehtml) {
// distribution folder
var dist = 'app/';
var source = 'src/'; // for abs path construction
var markupEngine = usehtml ? 'html' : 'jade';
var markupExt = '.' + markupEngine;
// main source folders
var srcLESS = source + 'less/';
var srcSCSS = source + 'scss/';
var srcHTML = source + markupEngine + '/';
var srcJS = source + 'js/';
// Shared config object
var config = {
// ---
// Paths
// ---
dist: dist,
distCSS: dist + 'css',
distJS: dist + 'js',
source: source,
srcLESS: srcLESS,
srcSCSS: srcSCSS,
srcHTML: srcHTML,
srcJS: srcJS,
html: {
index: [srcHTML + 'index' + markupExt],
views: [
srcHTML + '**/*' + markupExt,
'!'+srcHTML + 'index' + markupExt
],
templates: [
srcHTML + 'views/sidebar/*' + markupExt,
srcHTML + 'views/navbar/*' + markupExt,
srcHTML + 'views/layers/*' + markupExt,
srcHTML + 'views/filters/*' + markupExt,
srcHTML + 'views/modals/*' + markupExt
],
all: [srcHTML + '**/*' + markupExt]
},
less: {
styles: [srcLESS + 'styles.less'],
watch: [srcLESS + 'app/**/*.less'],
bootstrap: [srcLESS + 'bootstrap/bootstrap.less']
},
scss: {
styles: [srcSCSS + 'styles.scss'],
watch: [srcSCSS + 'app/**/*.scss'],
bootstrap: [srcSCSS + 'bootstrap.scss']
},
js: [srcJS + 'app.module.js', srcJS + 'modules/**/*.js', srcJS + 'custom/**/*.js'],
// ---
// Plugins
// ---
plato: {
js: srcJS + '**/*.js'
},
report: './report/',
tplcache: {
file: 'templates.js',
opts: {
standalone: false,
root: 'templates',
module: 'insight'
}
},
webserver: {
webroot: '.',
host: 'localhost',
port: '3000',
livereload: true,
directoryListing: false
},
prettify: {
indent_char: ' ',
indent_size: 3,
unformatted: ['a', 'sub', 'sup', 'b', 'i', 'u']
},
usemin: {
path: '.',
css: [$.minifyCss({ processImport: false }), 'concat', $.rev()],
// html: [$.minifyHtml({empty: true})],
vendor: [$.uglify( {preserveComments:'some'} ), $.rev()],
js: [$.ngAnnotate(), $.uglify( {preserveComments:'some'} ), $.rev()]
}
};
// scripts to check with jshint
config.lintJs = [].concat(config.js, config.distJS);
return config;
};
gulpfile.js
var argv = require('yargs').argv;
var usehtml = true;
var usertl = argv.usertl;
var usescss = argv.usescss;
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
gutil = require('gulp-util'),
gulpsync = require('gulp-sync')(gulp),
path = require('path'),
glob = require('glob'),
del = require('del'),
runSequence = require('run-sequence'),
config = require('./gulp.config')($, usehtml);
// production mode
var isProduction = false;
//---------------
// TASKS
//---------------
// APP LESS
gulp.task('styles', function () {
log('Compiling styles to CSS..');
var stylesSrc = usescss ? config.scss.styles : config.less.styles;
return gulp.src(stylesSrc)
.pipe(isProduction ? gutil.noop() : $.sourcemaps.init())
.pipe(usescss ? $.sass() : $.less())
.on("error", handleError)
.pipe($.if(usertl, $.rtlcss()))
.pipe(isProduction ? $.minifyCss({processImport: false}) : gutil.noop())
.pipe(isProduction ? gutil.noop() : $.sourcemaps.write())
.pipe(gulp.dest(config.distCSS));
});
// BOOSTRAP
gulp.task('bootstrap', function () {
log('Compiling Bootstrap..');
var bsSrc = usescss ? config.scss.bootstrap : config.less.bootstrap;
return gulp.src(bsSrc)
.pipe(isProduction ? gutil.noop() : $.sourcemaps.init())
.pipe(usescss ? $.sass() : $.less())
.on("error", handleError)
.pipe($.if(usertl, $.rtlcss()))
.pipe(isProduction ? $.minifyCss({processImport: false}) : gutil.noop())
.pipe(isProduction ? gutil.noop() : $.sourcemaps.write())
.pipe(gulp.dest(config.distCSS));
});
// HTML
gulp.task('markup', ['index', 'views']);
gulp.task('views', buildMarkup(config.html.views, config.dist));
gulp.task('index', ['templatecache'], buildMarkup(config.html.index, '.', false, true));
gulp.task('templatecache', ['clean-scripts'], buildMarkup(config.html.templates, config.dist + 'js', true));
// SERVER
// -----------------------------------
gulp.task('webserver', function () {
log('Starting web server.. ');
return gulp.src(config.webserver.webroot)
.pipe($.webserver(config.webserver));
});
//---------------
// WATCH
//---------------
// Rerun the task when a file changes
gulp.task('watch', function () {
log('Starting watch with live reload ...');
$.livereload.listen();
if (usescss) gulp.watch([config.scss.watch, config.scss.styles], ['styles']);
else gulp.watch([config.less.watch, config.less.styles], ['styles']);
if (usescss) gulp.watch(config.scss.bootstrap, ['bootstrap']);
else gulp.watch(config.less.bootstrap, ['bootstrap']);
gulp.watch(config.html.all, ['markup']);
gulp.watch(config.html.templates, ['templatecache']);
gulp
.watch([].concat(config.less.watch, config.html.views, config.html.templates, config.js))
.on('change', function (event) {
setTimeout(function () {
$.livereload.changed(event.path);
}, 1400);
});
});
/**
* Clean
*/
gulp.task('clean', ['clean-scripts', 'clean-styles', 'clean-markup']);
gulp.task('clean-scripts', function (cb) {
var js = config.distJS + '/*{js,map}';
clean(js, cb);
});
gulp.task('clean-styles', function (cb) {
var css = config.distCSS + '/*{css,map}';
clean(css, cb);
});
gulp.task('clean-markup', function (cb) {
var html = ['index.html', config.dist + 'views/'];
clean(html, cb);
});
gulp.task('clean-build', function (cb) {
log('Removing development assets');
var delFiles = [
config.distJS + '/' + config.tplcache.file,
config.distCSS + '/bootstrap.css',
config.distCSS + '/styles.css'
];
clean(delFiles, cb);
});
/**
* vet the code and create coverage report
*/
gulp.task('lint', function () {
log('Analyzing source with JSHint');
return gulp
.src(config.lintJs)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish', {verbose: true}))
.pipe($.jshint.reporter('fail'));
});
//---------------
// Visualizer report
//---------------
gulp.task('plato', function (done) {
log('Analyzing source with Plato');
log('Browse to /report/plato/index.html to see Plato results');
startPlatoVisualizer(done);
});
//---------------
// MAIN TASKS
//---------------
// build for production
gulp.task('build', [], function (cb) {
runSequence('clean', 'production', 'compile', 'clean-build', cb);
});
gulp.task('production', function () {
isProduction = true;
});
// default (no minify, sourcemaps and watch)
gulp.task('default', function (callback) {
runSequence('clean', 'compile', 'watch', 'done', callback);
}).task('done', done);
// serve development by default
gulp.task('serve', function (cb) {
runSequence('default', 'webserver', cb);
});
// optional serve production
gulp.task('serve-build', function (cb) {
runSequence('build', 'webserver', cb);
});
// run tasks without watch
gulp.task('compile', function (cb) {
runSequence(
'bootstrap',
'styles',
'templatecache',
'markup',
cb);
});
/////////////////
/**
* Error handler
*/
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
/**
* Build html templates
* #param {string} src source files folder
* #param {string} dst target folder
* #param {boolean} useTplcache Should generate angular template cache
* #return {stream}
*/
function buildMarkup(src, dst, useTplcache, useMin) {
return function () {
log('Compiling HTML...');
if (useTplcache) log('Creating AngularJS templateCache..');
return gulp.src(src)
.pipe(isProduction ? gutil.noop() : $.changed(dst, {extension: '.html'}))
.pipe($.if(!usehtml, $.jade({
locals: {
scripts: glob.sync(config.source + 'js/**/*.js')
}
})
)
)
.on("error", handleError)
.pipe($.htmlPrettify(config.prettify))
// .pipe($.angularHtmlify())
.pipe(isProduction && useMin ?
$.usemin(config.usemin)
: gutil.noop()
)
.pipe(useTplcache ?
$.angularTemplatecache(config.tplcache.file, config.tplcache.opts)
: gutil.noop()
)
.pipe(gulp.dest(dst))
;
}
}
/**
* Delete all files in a given path
* #param {Array} path - array of paths to delete
* #param {Function} done - callback when complete
*/
function clean(path, done) {
log('Cleaning: ' + $.util.colors.blue(path));
del(path, done);
}
/**
* Start Plato inspector and visualizer
*/
function startPlatoVisualizer(done) {
log('Running Plato');
var files = glob.sync(config.plato.js);
var excludeFiles = /.*\.spec\.js/;
var plato = require('plato');
var options = {
title: 'Plato Inspections Report',
exclude: excludeFiles
};
var outputDir = config.report + 'plato/';
plato.inspect(files, outputDir, options, platoCompleted);
function platoCompleted(report) {
var overview = plato.getOverviewReport(report);
log(overview.summary);
if (done) {
done();
}
}
}
/**
* Just to be polite :)
*/
function done() {
setTimeout(function () { // it's more clear to show msg after all
log('Done.. Watching code and reloading on changes..');
}, 500);
};
/**
* Standard log
*/
function log(msg) {
var prefix = '*** ';
gutil.log(prefix + msg);
}
It seems there are multiple errors in your launch config.
Some of the paths in your config are wrong. for example:
"${workspaceRoot}./node_modules/gulp/bin/gulp.js"
should be
"${workspaceRoot}/node_modules/gulp/bin/gulp.js"
${workspaceRoot} is a placeholder for the absolute path to your workspace. You cannot use relative path syntax like ./[relativepath] in launch.json. just replace . with ${workspaceRoot}.
If you are using "type": "node" in your launch config "program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js" should point to the index file of your node application and not to the gulp executable.
In your gulp file it looks like you are trying to debug a website. In this case you should use Debugger for Chrome or Debugger for Edge vscode extension
I am trying to integrate the JSONStore standalone app in my multipage application. When I am trying to initialize the collection I am getting the following error "Uncaught TypeError: undefined is not a function". One thing I want to know is, in Worklight version 6.0 I observed that underscore (Lo-Dash) templating was used. But nowhere I found the reference given to the lodash. Also, I didn't find the lodash file anywhere. can anyone please tell me how to do this?
Here is my javascript code
window.$ = window.jQuery = WLJQ;
currentPage = {};
currentPage.init = function(WL, jQuery, lodash) {
alert("current page ::init called");
'use strict';
//Dependencies
var $ = jQuery,
_ = lodash;
//CONSTANTS
var PEOPLE_COLLECTION_NAME = 'people',
KEY_VALUE_COLLECTION_NAME = 'keyvalue',
INIT_FIRST_MSG = 'PERSISTENT_STORE_NOT_OPEN',
NAME_FIELD_EMPTY_MSG = 'Name field is empty',
AGE_FIELD_EMPTY_MSG = 'Age field is empty',
ID_FIELD_EMPTY_MSG = 'Id field is empty',
EMPTY_TABLE_MSG = 'No documents found',
DESTROY_MSG = 'Destroy finished succesfully',
INIT_MSG = 'Collection initialized',
ADD_MSG = 'Data added to the collection',
REPLACE_MSG = 'Document replaced succesfully, call find.',
REMOVE_MSG = 'Documents removed: ',
COUNT_MSG = 'Documents in the collection: ',
CLOSE_ALL_MSG = 'JSONStore closed',
REMOVE_COLLECTION_MSG = 'Removed all data in the collection',
LOAD_MSG = 'New documents loaded from adapter: ',
PUSH_MSG_FAILED = 'Could not push some docs, res: ',
PUSH_MSG = 'Push finished',
PASS_CHANGED_MSG = 'Password changed succesfully';
$('#init').click(initCollection);
$('#destroy').click(destroy);
$('#add-data').click(addData);
$('#find-name').click(findByName);
$('#find-age').click(findByAge);
$('#find-all').click(findAll);
$('#find-id-btn').click(findById);
$('#replace').click(replace);
$('#remove-id-btn').click(removeById);
//Log messages to the console and status field
var _logMessage = function (msg, id) {
//Get reference to the status field
var status = _.isUndefined(id) ? $('div#status-field') : $(id);
//Put message in the status div
status.text(msg);
//Log message to the console
WL.Logger.info(msg);
};
//Show JSONStore document in a table
var _showTable = function (arr) {
if (_.isArray(arr) && arr.length < 1) {
return _logMessage(EMPTY_TABLE_MSG);
}
//Log to the console
WL.Logger.ctx({stringify: true, pretty: true}).info(arr);
var
//Get reference to the status field
status = $('div#status-field'),
//Table HTML template
table = [
'<table id="user_table" >',
'<tr>',
'<td><b>_id</b></td>',
'<td><b>name</b></td>',
'<td><b>age</b></td>',
'<td><b>json</b></td>',
'</tr>',
'<% _.each(people, function(person) { %>',
'<tr>',
'<td> <%= person._id %> </td>',
'<td> <%= person.json.name %> </td>',
'<td><%= person.json.age %></td>',
'<td><%= JSON.stringify(person.json) %></td>',
'</tr>',
'<% }); %>',
'</table>'
].join(''),
//Populate the HTML template with content
html = _.template(table, {people : arr});
//Put the generated HTML table into the DOM
status.html(html);
};
//Scroll to the top every time a button is clicked
$('button').on('click', function () {
$('html, body').animate({scrollTop: 0}, 'slow');
});
function initCollection() {
console.log("init collection method called");
alert("init collection method called");
//Get references to the input fields DOM elements
var usernameField = $('input#init-username'),
passwordField = $('input#init-password');
//Get values from the input fields
var username = usernameField.val() || '',
password = passwordField.val() || '';
//Create the optional options object passed to init
var options = {};
//Check if a username was passed
if (username.length > 0) {
options.username = username;
}
//If if a password was passed
if (password.length > 0) {
options.password = password;
}
//JSONStore collections metadata
var collections = {};
//Define the 'people' collection and list the search fields
collections[PEOPLE_COLLECTION_NAME] = {
searchFields : {name: 'string', age: 'integer'},
//-- Start optional adapter metadata
adapter : {
name: 'people',
add: 'addPerson',
remove: 'removePerson',
replace: 'replacePerson',
load: {
procedure: 'getPeople',
params: [],
key: 'peopleList'
}
}
//-- End optional adapter metadata
};
//Define the 'keyvalue' collection and use additional search fields
collections[KEY_VALUE_COLLECTION_NAME] = {
searchFields : {},
additionalSearchFields : { key: 'string' }
};
//Initialize the people collection
WL.JSONStore.init(collections, options)
.then(function () {
_logMessage(INIT_MSG);
_callEnhanceToAddKeyValueMethods();
})
.fail(function (errorObject) {
_logMessage(errorObject.msg);
});
}
Thanks in advance
regards
V.H.C
I observed that underscore(loadash) templating was used. But nowhere I
found the reference given to the loadash. Also, I didn't find the
loadash file anywhere. can anyone please tell me how to do this?
You can build your own version of lodash or use underscore.
The version of lodash used by worklight is in the WL_ variable. Looking at your code, maybe you want to replace _ = lodash with _ = WL_. Alternatively when you bring your own version lodash or underscore it will be assigned to the _ variable automatically.
Alternatively, you can use other string template libraries like Handlebars.js or basic string interpolation by modifying the String prototype.
I've got the below bit of code which pull back a list of the users facebook contacts along with their profile picture, however the images are not loading for each user, it is only showing the images for a few users.
fb.requestWithGraphPath('me/friends', {
fields : 'first_name,last_name,id,installed,picture.width(120).height(120),gender'
}, 'GET', function(e) {
if (e.success) {
var d = JSON.parse(e.result);
var pData = [];
var iData = [];
var row = d.data;
row = row.sort(sortByName)
for (var i = 0; i < d.data.length; i++) {
var img = row[i].picture.data.url
if (row[i].installed) {
pData.push({
properties : {
title : row[i].first_name + " " + row[i].last_name,
id : row[i].id,
image : img,
gender : row[i].gender,
accessoryType : Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE
},
template : Ti.UI.LIST_ITEM_TEMPLATE_DEFAULT
});
} else {
iData.push({
properties : {
title : row[i].first_name + " " + row[i].last_name,
id : row[i].id,
image : img,
accessoryType : Ti.UI.LIST_ACCESSORY_TYPE_DISCLOSURE
},
template : Ti.UI.LIST_ITEM_TEMPLATE_DEFAULT
});
}
}
var play = Ti.UI.createListSection({
headerTitle : 'Play with Facebook Friends',
items : pData
});
var invite = Ti.UI.createListSection({
headerTitle : 'Invite Facebook Friends',
items : iData
});
var listView = Ti.UI.createListView({
sections : [play, invite],
});
self.add(listView)
} else {
alert("Facebook Error");
}
})
The images are stored in var img = row[i].picture.data.url and pushed into the data array as part of image : img but not all images are loading.
Is there a way to force the images to load? and show a default image whilst they are loading?
Here is a link to complete example to do exactly what you are trying to accomplish abaove
http://www.clearlyinnovative.com/blog/post/34758524584/alloy-listview-facebook-friends#.UgexZGRATrg
I am a freshman on skydrive. then I want to use file picker in html, and copy the demo code from Interactive Live SDK. but the running result, the open window is not direct to file picker page, just direct to my setting redirect_uri page. so what's wrong with my demo page? thanks
<script src="http://js.live.net/v5.0/wl.js" type="text/javascript"></script>
<script type="text/JavaScript">
<!--
/////////////////////////////
WL.init({ client_id: '$my appID', redirect_uri: 'http://www.learnyouwant.com' });
WL.ui({
name: "skydrivepicker",
element: "downloadFile_div",
mode: "open",
select: "multi",
onselected: onDownloadFileCompleted,
onerror: onDownloadFileError
});
WL.login({ "scope": "wl.skydrive wl.signin" }).then(
function(response) {
openFromSkyDrive();
},
function(response) {
log("Failed to authenticate.");
}
);
function openFromSkyDrive() {
WL.fileDialog({
mode: 'open',
select: 'single'
}).then(
function(response) {
log("The following file is being downloaded:");
log("");
var files = response.data.files;
for (var i = 0; i < files.length; i++) {
var file = files[i];
log(file.name);
WL.download({ "path": file.id + "/content" });
}
},
function(errorResponse) {
log("WL.fileDialog errorResponse = " + JSON.stringify(errorResponse));
}
);
}
function log(message) {
var child = document.createTextNode(message);
var parent = document.getElementById('JsOutputDiv') || document.body;
parent.appendChild(child);
parent.appendChild(document.createElement("br"));
}
function onDownloadFileCompleted(response) {
var msg = "";
// For each folder selected...
if (response.data.folders.length > 0) {
for (folder = 0; folder < response.data.folders.length; folder++) {
// Use folder IDs to iterate through child folders and files as needed.
msg += "\n" + response.data.folders[folder].id;
}
}
// For each file selected...
if (response.data.files.length > 0) {
for (file = 0; file < response.data.files.length; file++) {
// Use file IDs to iterate through files as needed.
msg += "\n" + response.data.files[file].id;
}
}
log(msg);
};
function onDownloadFileError(responseFailed) {
log(responseFailed.error.message);
}
//-->
</script>
I found the reason. the redirect_uri must same with the filling in the app registeration.