让 Google 文件选择器与 drive.file 范围一起使用 [英] Getting Google file picker to work with drive.file scope

查看:16
本文介绍了让 Google 文件选择器与 drive.file 范围一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Google 文件选择器来选择一个文档,然后更新其权限.我不需要访问所有云端硬盘文件,只需要访问那些选定的文件.

I'm trying to use the Google file picker to select a document and then update its permissions. I don't need access to all Drive files, just those selected.

但是,当使用 https://www.googleapis.com/auth/drive.file 范围,当我尝试更改文档的权限时出现 404 错误.如果我使用 https://www.googleapis.com/auth/drive<,我不会收到此错误/a> 范围,但这给了我比我需要的更多的访问权限.

However, when using the https://www.googleapis.com/auth/drive.file scope, I'm getting a 404 error when I try to change the permissions of the doc. I don't get this error if I use the https://www.googleapis.com/auth/drive scope, but this gives me more access than I need.

有没有办法让文件选择器与更有限的 https://www.googleapis.com/auth/drive.file 范围?

Is there any way to get the file picker working with the more limited https://www.googleapis.com/auth/drive.file scope?

这是我的文件选择器代码:

Here's my file picker code:

 <!-- 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 ];
      }

推荐答案

感谢 Google Plus 上 Google Drive Developer 讨论中人们的帮助,回答我自己的问题:

Answering my own question thanks to help from folks on the Google Drive Developer discussion on Google Plus:

这确实有效.我在选择器实现中使用了错误的 App_ID - 我只需要在客户端 ID 的开头使用数字字符串.另一个问题,它不适用于本地主机,只能在生产中使用.

This does work. I was using the wrong App_ID in my picker implementation - I needed to use only the numeric string at the beginning of the client ID. The other problem, it doesn't work on localhost, only in production.

在此处进行完整讨论:https://plus.google.com/u/0/108228914813783364664/posts/RgvmZwJcbE8

这篇关于让 Google 文件选择器与 drive.file 范围一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆