How to upload a file using a URL in Google App application scripts

I am new to Google application scripting. I use the Googles function to access the DFA / DCM Trafficking and Reporting APIs through application scripts without using OAuth.

When I run the DCM report and then convert to Google Sheets, I cannot figure out how to use either the URLs that I supply to download the CSV.

Here is the code I'm using.

  var file =  DCM.Reports.run(profile.profileId,30792432);
  var file2 =  DCM.Files.get(30792432, file.id);
  //wait till running of the report is complete.
  file2 =  DCM.Files.get(30792432, file.id);
  var response = UrlFetchApp.fetch(file2.urls.browserUrl);

I am also trying to use:

  file2.urls.apiUrl(); 

for the UrlFetchApp team, but that didn't work either.

Any help on how to implement the URL to download the file as an object into which I can embed in Google Sheets would be greatly appreciated.

Thank!

+4
source share
1

ScriptApp apiurl. - :

var token = ScriptApp.getOAuthToken();

var headersOptions = { 
  Authorization : 'Bearer '  + token
  };

var options = { 
  headers : headersOptions
  };

var csvDoc = UrlFetchApp.fetch(file2.url.apiurl, options);
+1

Source: https://habr.com/ru/post/1629822/


All Articles