Hello,
could you please help me to understand how the DropBox API call should be done to get a file from Dropbox to Google Drive?
I've already authenticate it using OAuth2 but I can't set up the API request.
function downloadFileFromDropBox()
{
var confirmAuthorization=getBoxService_().getAccessToken();
//https://ent.box.com/s/78s1vk70ecm3gzx9zpl85fudc0pjy57g
var options={
'method' : 'post',
'Authorization': 'Bearer ' + confirmAuthorization,
'Dropbox-API-Arg': '{"path": "/Scrum_model_feature.xlsx"}',
'muteHttpExceptions': 'true'
}
var response = UrlFetchApp.fetch('https://content.dropboxapi.com/2/files/download', {headers:options}
);
var result=DriveApp.createFile(response);
result.setName("GTMList.xlsx");
result.setStarred(true);
}
Exception: Request failed for
https://content.dropboxapi.com returned code 401. Truncated server response: {"error_summary": "invalid_access_token/", "error": {".tag": "invalid_access_token"}} (use muteHttpExceptions option to examine full response)
I have another function which lists all the folders on DropBox. It works well.
function getFoldersList() {
var confirmAuthorization=getBoxService_().getAccessToken();
var response = UrlFetchApp.fetch('https://api.box.com/2.0/folders/0/items?fields=name,type', {
headers: {
'Authorization': 'Bearer ' + confirmAuthorization
}
});
var result = JSON.parse(response.getContentText());
var items = result.entries;
var folders = [];
for (var i=0; i<items.length; i++) {
if (items[i].type === "folder") {
folders.push({name: items[i].name, id: items[i].id});
}
}
Logger.log(folders);
}
Thank you.