Javascript [google drive api]如何处理google api';s get()alt=媒体响应
我一直在尝试在我的angularjs应用程序中实现驱动API。我想下载一个pdf文件,所以我使用以下代码Javascript [google drive api]如何处理google api';s get()alt=媒体响应,javascript,angularjs,api,google-drive-api,Javascript,Angularjs,Api,Google Drive Api,我一直在尝试在我的angularjs应用程序中实现驱动API。我想下载一个pdf文件,所以我使用以下代码 $scope.getFile = function(id) { console.log(id); //console.log(fileId); if (id != null) { var request = gapi.client.drive.files.get({ 'fileId': id, 'alt': 'media' });
$scope.getFile = function(id) {
console.log(id);
//console.log(fileId);
if (id != null) {
var request = gapi.client.drive.files.get({
'fileId': id,
'alt': 'media'
});
request.execute(function(resp) {
console.log('response: ' + resp);
});
}
}
但是我的console.log打印“false”。我不知道为什么它真的让我发疯,我检查了inspect元素中的network选项卡,发现响应正确地为base64字符串
我还调用了
atob(resp)
,这表示要解码的文本没有正确编码。但是我使用了一个在线base64解码器,它工作得非常好,pdf正在打开。请帮助我,我被困在这里只需使用然后
而不是执行
:
var request = gapi.client.drive.files.get({
'fileId': id,
'alt': 'media'
});
request.then(function(resp) {
console.log('response: ' + resp);
});
非常感谢。你救了我一天!