让Google文件选取器与drive.file作用域一起工作 [英] Getting Google file picker to work with drive.file scope

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

问题描述

我试图使用Google文件选择器来选择文档,然后更新其权限。我不需要访问所有选中的云端硬盘文件。 然而,当使用 https:/ /www.googleapis.com/auth/drive.file 作用域,当我尝试更改文档的权限时,出现404错误。如果我使用 https://www.googleapis.com/auth/drive 范围,但是这给了我更多的访问权限。



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



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

 <! - 标准的Google Loader脚本。 - > 
< script src =http://www.google.com/jsapi>< / script>
< script type =text / javascript>


//使用Google Loader脚本加载google.picker脚本。
//google.setOnLoadCallback (createPicker);
google.load('picker','1');

//创建并呈现Picker对象
函数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(googleoglecrick.Feature.MULTISELECT_ENABLED)
.setAppId(<%= ENV ['GOOGLE_ID']%>)
.setOAuthToken(<%= current_user.token%>)//可选:使用的授权令牌在当前的Drive API会话中。
.addView(view)
.addView(new google.picker.DocsUploadView())
.setCallback(pickerCallback)
.build();
picker.setVisible(true);

}


//回调执行。
函数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 Drive Developer上关于Google Plus的讨论中的帮助:



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



全面讨论: https://plus.google.com/u/0/108228914813783364664/posts/RgvmZwJcbE8


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.

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.

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

解决方案

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

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.

Full discussion here: https://plus.google.com/u/0/108228914813783364664/posts/RgvmZwJcbE8

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

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