3

Following the Realtime-Playground example, I am trying to enable "open file" in my application. Authorization works correct, and an empty file is created on gDrive. Although the code for creating a popup for file selection is not working. The following code is part of rt-playground and I am using the same:

var popupOpen = function () {
      var token = gapi.auth.getToken().access_token;
      var view = new google.picker.View(google.picker.ViewId.DOCS);
      view.setMimeTypes("application/vnd.google-apps.drive-sdk." + realTimeOptions.appId);
      var picker = new google.picker.PickerBuilder()
          .enableFeature(google.picker.Feature.NAV_HIDDEN)
          .setAppId(realTimeOptions.appId)
          .setOAuthToken(token)
          .addView(view)
          .addView(new google.picker.DocsUploadView())
          .setCallback(openCallback)
          .build();
      picker.setVisible(true);
    }

I have also connected the above function to a button. When I click the button before authorization I get the following error

TypeError: 'undefined' is not an object (evaluating 'gapi.auth.getToken')

Which I guess is the correct behaviour. When I click the button after authorization I am getting the following error:

Uncaught TypeError: Cannot read property 'View' of undefined 

The error comes from this line of the code:

      var view = new google.picker.View(google.picker.ViewId.DOCS);

On my index.html page I have added all the scripts that are used in the rt-playground, and since authorization is working, I guess the problem is not caused by that. Any feedback would be appreciated.

This is my code (used for tests but still, feedback are welcome).

Ps: One (of the) thing(s) I am not sure if I do correctly is setting the appID. After looking in the API console I did not find any attribute named like that, so I tried using the Project ID and the product name.

Update

By adding google.load('picker', '1'); inside my index.html page it has worked. Although this code does not exist in the realtime-playground, so I am not sure why i need to use it..

Giannis
  • 5,286
  • 15
  • 58
  • 113

1 Answers1

3

Please check this documentation about integrating Google Picker with Drive. google.load('picker', '1'); There is a full sourcecode of js integration.

JunYoung Gwak
  • 2,967
  • 3
  • 21
  • 35
  • I read the above documentation. If you notice the update, I ask why google.load is required as its not included in rt-playground, which is also making using of Picker. https://github.com/latusaki/realtime-playground – Giannis Jul 01 '13 at 10:49
  • 1
    It actually does make that call: https://github.com/googledrive/realtime-playground/blob/master/js/rtpg.ui.js#L130 – Cheryl Simon Jul 06 '13 at 16:51