Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.6k views
in Technique[技术] by (71.8m points)

ruby on rails - Getting Google file picker to work with drive.file scope

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 ];
      }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...