After replying to another last post ( Thomas van Latum ), I tried the proposed api document and got an interesting result ... here is the test code that I used and which works well, except that the file is in xlsx format and not in xls, but these days this is not necessarily a problem:
function googleOAuth_(name,scope) { var oAuthConfig = UrlFetchApp.addOAuthService(name); oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope); oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken"); oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); oAuthConfig.setConsumerKey('anonymous'); oAuthConfig.setConsumerSecret('anonymous'); return {oAuthServiceName:name, oAuthUseToken:"always"}; } function test(){ var id = 'spreadsheet_ID' var url = 'https://docs.google.com/feeds/'; var doc = UrlFetchApp.fetch(url+'download/spreadsheets/Export?key='+id+'&exportFormat=xls', googleOAuth_('docs',url)).getBlob() DocsList.createFile(doc).rename('newfile.xls') }
Note: if you did not rename it, its default name is Export.xlsx , it might be more useful to get its identifier so that you can use it later ... so the last line could be like this:
var xlsfileID = DocsList.createFile(doc).getId()
EDIT: to start the authorization process, try such a small function, run it from the script editor
function autorise(){ // function to call to authorize googleOauth var id=SpreadsheetApp.getActiveSpreadsheet().getId(); var url = 'https://docs.google.com/feeds/'; var doc = UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=html&format=html&id='+id, googleOAuth_('docs',url)).getContentText(); }
source share