Problem
The problem I'am having is that when i try to call a second WL.api
from my parent, because i'am in need of the data
output from the first api, the script
seem to break. I don't get any error response from the second api. If someone could point me in the right direction with this problem I would be grateful.
Note: The first call to fetch the folders work and i get the wanted data. It's when i try to make the second call to fetch the files in the wanted folder that breaks.
My function
is is called from a button's onClick
event, this is my function
:
function getFolders() {
WL.api({
path: "me/skydrive/files",
method: "GET"
}).then(
function(response) {
var folders = response.data;
$.each(folders, function () {
var folder = this;
if (folder.name == 'FooBar') {
WL.api({
path: "/" + folder.id + "/files",
method: "GET"
}).then(
function(response2) {
var files = response2.data;
$.each(files, function() {
var file = this;
if (file.name == 'Foo') {
alert(file.id);
}
});
},
function(responseFailed) {
alert(responseFailed.error.message);
}
);
}
});
},
function(responseFailed) {
alert(responseFailed.error.message);
}
);
}
Maybe you must check that you are receiving a folder or an album, and not a file, because I think that you cant browse for files in a file.
i.e
if (folder.type == 'folder' || folder.type == 'album')
if (folder.name == 'FooBar') { //do the call }
before you calling the next api request.
Try if that helps