我正在尝试使用 Google 文件选择器来选择一个文档,然后更新它的权限。我不需要访问所有云端硬盘文件,只需要访问那些选定的文件。
但是,在使用https://www.googleapis.com/auth/drive.file范围时,当我尝试更改文档的权限时出现 404 错误。如果我使用https://www.googleapis.com/auth/drive范围,我不会收到此错误,但这给了我比我需要的更多的访问权限。
有没有办法让文件选择器在更有限的https://www.googleapis.com/auth/drive.file范围内工作?
这是我的文件选择器代码:
<!-- The standard Google Loader script. -->
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
// Use the Google Loader script to load the google.picker script.
//google.setOnLoadCallback(createPicker);
google.load('picker', '1');
// Create and render a Picker object
function createPicker() {
var view = new google.picker.DocsView(google.picker.ViewId.DOCS);
view.setMode(google.picker.DocsViewMode.LIST);
//view.setMimeTypes("image/png,image/jpeg,image/jpg");
var picker = new google.picker.PickerBuilder()
//.enableFeature(google.picker.Feature.NAV_HIDDEN)
//.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
.setAppId("<%= ENV['GOOGLE_ID']%>")
.setOAuthToken("<%= current_user.token %>") //Optional: The auth token used in the current Drive API session.
.addView(view)
.addView(new google.picker.DocsUploadView())
.setCallback(pickerCallback)
.build();
picker.setVisible(true);
}
// callback implementation.
function pickerCallback(data) {
var url = 'nothing';
if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
url = doc[google.picker.Document.URL];
title = doc.name;
id = doc.id;
type = doc.type;
embed = doc[google.picker.Document.EMBEDDABLE_URL ];
}