Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. var CLIENT_ID = 'MY_CLIENT_ID';
  2.  
  3. var SCOPES = ['https://www.googleapis.com/auth/drive'];
  4.  
  5. var accArr = new Array();
  6.  
  7. function addGapi(authResult){
  8. if (authResult && !authResult.error) {
  9. accArr.push(gapi);
  10. var option = $(create('option'));
  11. option.val(accArr.length - 1);
  12. option.text(accArr.length - 1);
  13. $('#account-select').append(option);
  14. } else {
  15.  
  16. }
  17. }
  18.  
  19. /**
  20. * Initiate auth flow in response to user clicking authorize button.
  21. *
  22. * @param {Event} event Button click event.
  23. */
  24. function handleAuthClick(event) {
  25. gapi.auth.authorize(
  26. {
  27. client_id: CLIENT_ID,
  28. scope: SCOPES,
  29. immediate: false,
  30. response_type: 'token',
  31. approval_prompt: 'force'},
  32. addGapi);
  33. return false;
  34. }
  35. var whichAccountGlobal;
  36. function loadDriveApi(num) {
  37. var whichAccount = $('#account-select').find(':selected').val();
  38. whichAccountGlobal = whichAccount;
  39. if (accArr[whichAccount]){
  40. accArr[whichAccount].client.load('drive', 'v2', listFiles);
  41. }
  42. }
  43. /**
  44. * Print files.
  45. */
  46. function listFiles() {
  47. var request = accArr[whichAccountGlobal].client.drive.files.list({
  48. 'maxResults': 50
  49. });
  50.  
  51. request.execute(function(resp) {
  52. var table = $('#contentTable');
  53. var files = resp.items;
  54. if (files && files.length > 0) {
  55. for (var i = 0; i < files.length; i++) {
  56. var file = files[i];
  57. var tr = $(create('tr'));
  58. var td = $(create('td'));
  59. td.width('50%');
  60. var div =$(create('div'));
  61. div.html(file.title);
  62. td.append(div);
  63. tr.append(td);
  64.  
  65. td = $(create('td'));
  66. td.width('20%');
  67. div =$(create('div'));
  68. div.html(file.size);
  69. td.append(div);
  70. tr.append(td);
  71.  
  72. td = $(create('td'));
  73. td.width('30%');
  74. div =$(create('div'));
  75. div.html(file.id);
  76. td.append(div);
  77. tr.append(td);
  78.  
  79. $(table).append(tr);
  80. }
  81. } else {
  82.  
  83. }
  84. });
  85. }
  86.  
  87. <link href="google_drive/quickstart.css" rel="stylesheet" type="text/css"/>
  88.  
  89. <script src="https://apis.google.com/js/client.js"></script>
  90. <script src="google_drive/quickstart.js?v=1.1" type="text/javascript"></script>
  91. <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
  92. <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  93. <script src="misc/functions.js" type="text/javascript"></script>
  94. </script>
  95. </head>
  96. <body>
  97. <div>
  98. <div id="authorize-div">
  99. <span>
  100. Authorize access to Drive API
  101. </span>
  102. <!--Button for the user to click to initiate auth sequence -->
  103. <button id="authorize-button" onclick="handleAuthClick(event)">
  104. Authorize
  105. </button>
  106. <button id="authorize-button" onclick="authDrop(event)">
  107. Authorize DROPBOX
  108. </button>
  109. <button id="list-button" onclick="loadDriveApi(50)">
  110. list files
  111. </button>
  112. <select id="account-select">
  113. <option value = -1>
  114. choose
  115. </option>
  116. </select>
  117. </div>
  118. <pre id="output">
  119. </pre>
  120. </div>
  121. <div>
  122. <table id="headerTable" class="data-table">
  123. <tr>
  124. <th style="width:50%">
  125. file name
  126. </th>
  127. <th style="width:20%">
  128. size
  129. </th>
  130. <th style="width:30%">
  131. <th>
  132. ID
  133. </th>
  134. </tr>
  135. </table>
  136. <table id="contentTable" class="data-table">
  137. </table>
  138. </div>
  139. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement