[英]Access google drive file content from JavaScript
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. 我有一个web / html5应用程序,我向用户提供了一个功能,可以显示经过身份验证的用户的Google云端硬盘内容文件并选择它们。
I use with success google.picker UI interface and it works pretty well. 我成功使用google.picker UI界面,效果很好。 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. 有一次用户从UI中选择了文件,调用了
pickerCallback
,我得到了用户选择的对象属性列表。
driveError
: "ERROR" and driveSuccess
: false driveError
:“ERROR”和driveSuccess
:false gapi
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. 这与身份验证,imo有关,但根据Google本身的最新帖子,TOKEN管理已被弃用并实际删除。
How can I read a content of the picked by the user file form Google Drive ? 如何阅读Google云端硬盘用户文件所选内容?
您是否使用API控制台中的实际值替换上面代码中的MY_APP_ID
, MY_API_KEY
和MY_CLIENT_ID
占位符?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.