Reputation: 62265
I have a web/html5 applicaton where I provide to a user a functionality to visualize authenticated user's Google Drive content files and pick them.
I use with success google.picker UI interface and it works pretty well. Example:
var view = new google.picker.View(google.picker.ViewId.DOCS);
var picker = new google.picker.PickerBuilder()
.enableFeature(google.picker.Feature.NAV_HIDDEN)
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
.setAppId('MY_CLIENT_ID')
.addView(view)
.setCallback(pickerCallback)
.build();
picker.setVisible(true);
One time user picked the file(s) from the UI, the pickerCallback
is called and I get a list of object properties selected by the user.
driveError
: "ERROR" and driveSuccess
: falsegapi
My attempt was like:
gapi.client.setApiKey('MY_API_KEY');
gapi.client.load('drive', 'v2', function () {
var scopes = 'https://www.googleapis.com/auth/drive';
gapi.auth.authorize({ client_id: "MY_CLIENT_ID", scope: scopes, immediate: true },
function () {
//TOKEN IS ALWAYS NULL !!
var myToken = gapi.auth.getToken();
gapi.client.request({
'path': '/drive/v2/files/' + file.id,
'method': 'GET',
callback: function (theResponseJS, theResponseTXT) {
var myXHR = new XMLHttpRequest();
myXHR.open('GET', theResponseJS.downloadUrl, true);
myXHR.onreadystatechange = function (theProgressEvent) {
if (myXHR.readyState == 4) {
if (myXHR.status == 200) {
//200=OK
console.log(myXHR.response);
}
}
}
myXHR.send();
}
});
}
);
});
Here is something to do with authentication, imo, but according to the latest posts from Google itself, TOKEN management was deprecated and actually removed.
How can I read a content of the picked by the user file form Google Drive ?
Upvotes: 3
Views: 1967
Reputation: 15024
Are you replacing the MY_APP_ID
, MY_API_KEY
and MY_CLIENT_ID
placeholders in your code above with real values from the APIs Console?
Upvotes: 1