google drive download document using javascript :can't download files -


i have download documents google drive using google drive api java. want use javascript instead of java. using drive api client libraries java script code. using below code achieving this

function downloadfile(file, callback) {   if (file.downloadurl) {     var accesstoken = gapi.auth.gettoken().access_token;     var xhr = new xmlhttprequest();     xhr.open('get', file.downloadurl);     xhr.setrequestheader('authorization', 'bearer ' + accesstoken);     xhr.onload = function() {       callback(xhr.responsetext);     };     xhr.onerror = function() {       callback(null);     };     xhr.send();   } else {     callback(null);   } } 

my problem can able display file names , contents. can't download files. need code? how can save files in local system. suggestions ? note: can value in file.downloadurl if paste downloadurl in browser won't give result ,just show blank page.

"if paste downloadurl in browser won't give result" correct because when using browser there no authentication header. if check status see 401 error.

i use "authorization: 'oauth ' + gapi.auth.gettoken()['access_token']" rather 'bearer'. i'm not sure if significant.

are sure downloadurl current? short-lived attribute, it's possible link has expired.

it's possible access token invalid. burcu said, answer within response , status xhr get.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -