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
: false gapi
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 ?
您是否使用API控制台中的实际值替换上面代码中的MY_APP_ID
, MY_API_KEY
和MY_CLIENT_ID
占位符?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.