For an HTML / JavaScript solution, consider the following links:
https://developers.google.com/drive/quickstart-js
https://www.youtube.com/watch?v=09geUJg11iA
https://developers.google.com/drive/web/auth/web-client
Here's the easiest way to use JavaScript, most of the complexity in authorizing WebApp. The example below reads the file identifiers, names and descriptions in the folder you specify.
- go to: https://cloud.google.com/console/project and create a new project "xyz"
- Select "API and auth", disable the ones you do not need, enable the "Drive API"
- Select "Credentials",
press the "CREATE NEW CLIENT ID" button
x web application
Javascript authorized sources: " https://googledrive.com/ "
Authorized redirect URI: " https://googledrive.com/oauth2callback "
this will lead to:
Customer ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
Email Address: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com
Client Secret: xxxxxxxxxxxxxxxxxxxx
URI Redirection: https://googledrive.com/oauth2callback
Javascript Origins: https://googledrive.com/
- in the code below, replace
CLIENT_ID from xxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
FOLDER_ID with the identifier that you see in the address bar of the folder,
https://drive.google.com/?tab=mo&authuser=0#folders/xxxxxxxxxxxxxxxxxxx
- run it, authorize
I don’t know if you read JS, the code can follow from bottom to top, I made it as simple as possible.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script> var FOLDER_ID = '.xxxxxxxxxxxxxxxxxx'; // the folder files reside in var CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com'; var SCOPE = //'https://www.googleapis.com/auth/drive'; [ 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', // for description, ]; function rsvpCB(resp) { var picAlbumLst = '<ul>\n'; for (i=0; i<resp.items.length; i++) picAlbumLst += ( ' <li>'+resp.items[i].id+', '+resp.items[i].title+', '+resp.items[i].description+'</li>\n'); picAlbumLst += "</ul>\n"; $('#container').append(picAlbumLst); } function rqstCB() { //test @ https://developers.google.com/drive/v2/reference/files/list var rv = gapi.client.drive.files.list({ 'q': '"'+FOLDER_ID+'" in parents and trashed = false', 'fields' : 'items(id,title,description)' //'items(id,title,description,indexableText)' }).execute(rsvpCB); } // authorization server reply function onAuthResult(authResult) { var authButton = document.getElementById('authorizeButton'); authButton.style.display = 'none'; if (authResult && !authResult.error) { // access token successfully retrieved gapi.client.load('drive', 'v2', rqstCB); } else { // no access token retrieved, force the authorization flow. authButton.style.display = 'block'; authButton.onclick = function() { checkAuth(false); } } } // check if the current user has authorized the application. function checkAuth(bNow) { gapi.auth.authorize({'client_id':CLIENT_ID, 'scope':SCOPE, 'immediate':bNow}, onAuthResult); } // called when the client library is loaded, look below function onLoadCB() { checkAuth(true); } </script> <script src="https://apis.google.com/js/client.js?onload=onLoadCB"></script> <body style="background-color: transparent;"> <input type="button" id="authorizeButton" style="display: none" value="Authorize" /> <div id="container"> </div> </body>
source share