Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CLIENT_ID = 'MY_CLIENT_ID';
- var SCOPES = ['https://www.googleapis.com/auth/drive'];
- var accArr = new Array();
- function addGapi(authResult){
- if (authResult && !authResult.error) {
- accArr.push(gapi);
- var option = $(create('option'));
- option.val(accArr.length - 1);
- option.text(accArr.length - 1);
- $('#account-select').append(option);
- } else {
- }
- }
- /**
- * Initiate auth flow in response to user clicking authorize button.
- *
- * @param {Event} event Button click event.
- */
- function handleAuthClick(event) {
- gapi.auth.authorize(
- {
- client_id: CLIENT_ID,
- scope: SCOPES,
- immediate: false,
- response_type: 'token',
- approval_prompt: 'force'},
- addGapi);
- return false;
- }
- var whichAccountGlobal;
- function loadDriveApi(num) {
- var whichAccount = $('#account-select').find(':selected').val();
- whichAccountGlobal = whichAccount;
- if (accArr[whichAccount]){
- accArr[whichAccount].client.load('drive', 'v2', listFiles);
- }
- }
- /**
- * Print files.
- */
- function listFiles() {
- var request = accArr[whichAccountGlobal].client.drive.files.list({
- 'maxResults': 50
- });
- request.execute(function(resp) {
- var table = $('#contentTable');
- var files = resp.items;
- if (files && files.length > 0) {
- for (var i = 0; i < files.length; i++) {
- var file = files[i];
- var tr = $(create('tr'));
- var td = $(create('td'));
- td.width('50%');
- var div =$(create('div'));
- div.html(file.title);
- td.append(div);
- tr.append(td);
- td = $(create('td'));
- td.width('20%');
- div =$(create('div'));
- div.html(file.size);
- td.append(div);
- tr.append(td);
- td = $(create('td'));
- td.width('30%');
- div =$(create('div'));
- div.html(file.id);
- td.append(div);
- tr.append(td);
- $(table).append(tr);
- }
- } else {
- }
- });
- }
- <link href="google_drive/quickstart.css" rel="stylesheet" type="text/css"/>
- <script src="https://apis.google.com/js/client.js"></script>
- <script src="google_drive/quickstart.js?v=1.1" type="text/javascript"></script>
- <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
- <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
- <script src="misc/functions.js" type="text/javascript"></script>
- </script>
- </head>
- <body>
- <div>
- <div id="authorize-div">
- <span>
- Authorize access to Drive API
- </span>
- <!--Button for the user to click to initiate auth sequence -->
- <button id="authorize-button" onclick="handleAuthClick(event)">
- Authorize
- </button>
- <button id="authorize-button" onclick="authDrop(event)">
- Authorize DROPBOX
- </button>
- <button id="list-button" onclick="loadDriveApi(50)">
- list files
- </button>
- <select id="account-select">
- <option value = -1>
- choose
- </option>
- </select>
- </div>
- <pre id="output">
- </pre>
- </div>
- <div>
- <table id="headerTable" class="data-table">
- <tr>
- <th style="width:50%">
- file name
- </th>
- <th style="width:20%">
- size
- </th>
- <th style="width:30%">
- <th>
- ID
- </th>
- </tr>
- </table>
- <table id="contentTable" class="data-table">
- </table>
- </div>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement