Google Drive API-列出与我在应用程序中共享的文件,这些文件仅对由应用程序创建的文件具有读写权限(权限auth / drive.file)

时间:2019-01-22 22:01:20

标签: javascript google-drive-api

我正在测试要与Google api共享文件的方式,据我了解,我了解如何通过用户权限共享与我共享的ams,因为我需要通过应用程序在该应用程序上进行读写操作。共享文件的人的一面,我看不到它,因为我注意到api不会在应用程序的驱动器中查询文件的读取权限,只是将权限设置为“ https://www.googleapis.com/auth/drive.file”,因为我只希望我的应用有权访问她创建的文件。

所有者(api中的列表)->共享->用户(api中的列表)


/////////CODE SHARED FILE OWNER

var request1 = gapi.client.request({
        'path': '/drive/v3/files/' + fileId + '/permissions',
        'method': 'POST',
        'headers': {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + sTokenDrive
        },
        'body':{
          'role': 'writer',
          'type': 'user',
          'emailAddress' : 'user@gmail.com'
        }
      });
      request1.execute(function(resp) {
        console.log(resp);
      });



////////CODE LIST FILE USER


<script src="https://apis.google.com/js/api.js"></script>
<script>
  /**
   * Sample JavaScript code for drive.files.list
   * See instructions for running APIs Explorer code samples locally:
   * https://developers.google.com/explorer-help/guides/code_samples#javascript
   */

  function authenticate() {
    return gapi.auth2.getAuthInstance()
        .signIn({scope: "https://www.googleapis.com/auth/drive.file"})
        .then(function() { console.log("Sign-in successful"); },
              function(err) { console.error("Error signing in", err); });
  }
  function loadClient() {
    return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/drive/v3/rest")
        .then(function() { console.log("GAPI client loaded for API"); },
              function(err) { console.error("Error loading GAPI client for API", err); });
  }
  // Make sure the client is loaded and sign-in is complete before calling this method.
  function execute() {
    return gapi.client.drive.files.list({
      "corpus": "user",
      "q": "sharedWithMe = true"
    })
        .then(function(response) {
                // Handle the results here (response.result has the parsed body).
                console.log("Response", response);
              },
              function(err) { console.error("Execute error", err); });
  }
  gapi.load("client:auth2", function() {
    gapi.auth2.init({client_id: 'CLIENT_ID'});
  });
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>

0 个答案:

没有答案