Skip to content

Instantly share code, notes, and snippets.

@tanyagupta
Last active January 2, 2017 19:26
Show Gist options
  • Save tanyagupta/bcdefd4e5a3f841d8369608de8dcb8ec to your computer and use it in GitHub Desktop.
Save tanyagupta/bcdefd4e5a3f841d8369608de8dcb8ec to your computer and use it in GitHub Desktop.
UrlFetchApp with Drive (multiple pages)
var all_results ={};
var response = UrlFetchApp.fetch("https://www.googleapis.com/drive/v3/files?q="+mime_type,params);
var result=JSON.parse(response.getContentText()) ;
for (var i in result['files']) {
all_results[result['files'][i]['id']] = result['files'][i]['name'];
}
while (result['nextPageToken']) {
var pageToken = encodeURIComponent(result['nextPageToken']);
var new_call = "https://www.googleapis.com/drive/v3/files?"+"pageToken="+pageToken+"&q="+mime_type;
response = UrlFetchApp.fetch(new_call, params);
result=JSON.parse(response.getContentText())
for (var i in result['files']) {
all_results[result['files'][i]['id']] = result['files'][i]['name'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment