Skip to content

Commit

Permalink
Add minimal PoC of reading files from Drive.
Browse files Browse the repository at this point in the history
  • Loading branch information
asolove committed Jan 31, 2023
1 parent 5d0163d commit e1e1978
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,32 @@ window.handleAuthClick = function() {
}
}

/**
* Print metadata for first 10 files.
*/
async function listFiles() {
let response;
try {
response = await gapi.client.drive.files.list({
'pageSize': 10,
'fields': 'files(id, name)',
});
} catch (err) {
document.getElementById('content').innerText = err.message;
return;
}
const files = response.result.files;
if (!files || files.length == 0) {
document.getElementById('content').innerText = 'No files found.';
return;
}
// Flatten to string to display
const output = files.reduce(
(str, file) => `${str}${file.name} (${file.id})\n`,
'Files:\n');
document.getElementById('files').innerText = output;
}

/**
* Sign out the user upon button click.
*/
Expand Down
2 changes: 2 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
</div>
</div>

<div id="files"></div>

<script src="build/example.js"></script>

<script async defer src="https://apis.google.com/js/api.js" onload="gapiLoaded()"></script>
Expand Down

0 comments on commit e1e1978

Please sign in to comment.