Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ];
      }
like image 398
Kim Avatar asked Jun 15 '13 02:06

Kim


1 Answers

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

like image 119
Kim Avatar answered Sep 28 '22 04:09

Kim