当我请求Google Drive文件的downloadUrl字段时,我收到了401 Unauthorized响应。我做错了什么?
编辑:为了澄清,文件权限设置为public(test.txt),我可以访问文件的元数据以获取downloadUrl(如下面的示例代码所示)。那么为什么我能够使用/ files / {id}?key = {api_key}端点而不是downloadUrl链接呢?根据{{3}},您应该能够在数据所有者已识别为公开的数据时使用API密钥,例如公共日历或博客。"
https://developers.google.com/console/help/new/#usingkeys
var xhr = new XMLHttpRequest();
xhr.open("get", "https://www.googleapis.com/drive/v2/files/0Bzim72JjnlIWRFlURmRrX3N6NEE?key=AIzaSyDo66jOFuHllu3r3PwKcZaUd7N9ho9l9WU");
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
var download = new XMLHttpRequest();
download.open("get", JSON.parse(xhr.responseText)['downloadUrl']);
download.onreadystatechange = function(){
if(download.readyState === 4){
console.log(download.status);
}
};
download.send();
}
};
xhr.send();