Upload files to application drive account via Picker API

Google Picker API enables to pick files from Google Drive account or upload files to Google Drive account. With few lines of javascript code one can create sofisticated file upload UI.

How to include Google Picker

<script src="http://www.google.com/jsapi></script>
google.setOnLoadCallback(createPicker);
google.load('picker', '1');
/** Create picker object. */
function createPicker() {
 // Use DocsUploadView to upload documents to Google Drive.
    var uploadView = new google.picker.DocsUploadView();
    var picker = new google.picker.PickerBuilder().
        addView(uploadView).
        setAppId("xxxxxxxxxxxxxxxxxx").
        // setOAuthToken(ACCESS_TOKEN).
        setCallback(pickerCallback).
        build();
     picker.setVisible(true);
}
/** A simple callback implementation. */
function pickerCallback(data) {
    if (data.action == google.picker.Action.PICKED) {
        var fileId = data.docs[0].id;
        alert('The user selected: ' + fileId);
    }
}

Setting OAuth token doesn't work for file upload

Although it is a really cool widget it doesn't support uploading files to an application account using access token. It is possible only to view and pick files using access token. This makes the widget useless since there is probably no workaround if we don't want expose application account credentials to users.

Feature request was probably already accepted, but at the time of writing it doesn't work yet.

Comments

Popular posts from this blog

Hibernate delete and update queries with joins

Access application Google Drive account from javascript without client side authorization dialog

MyBatis calling Oracle stored procedures