Is there anyway to get private file of user with drive.file scope

半世苍凉 提交于 2021-02-11 13:55:11

问题


I want to get drive file of user (metadata, content, downloadUrl) not created by my application with access token have only drive.file scope. Can anyone have a solution for this one? Thank you.

 gapi.client.load('drive', 'v3', () => {
  gapi.auth.setToken({
    access_token: user.services.google.accessToken,
    expires_in: user.services.google.expiresAt,
  });
  gapi.client.drive.files.get({
    fileId: file.id,
    fields: 'webContentLink',
  }).then( test => {
    console.log('test', test);
  })
});

回答1:


You need to have access to user's file in order to obtain the webContentLink

You can incorporate in your script a function that allows the user to share his file with you, something like:

drive.permissions.create({
    resource: {
        'type': 'user',
        'role': 'reader',
        'emailAddress': 'YOUR EMAIL'
    }, 
        fileId: file.id,
    }
...);


来源:https://stackoverflow.com/questions/59283307/is-there-anyway-to-get-private-file-of-user-with-drive-file-scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!