我正在开发一个Java-JSF Web应用程序,其中显示一个弹出窗口,以便让用户从Google Drive中选择一个文档进行下载。从刚刚检索到的id获取Google Doc
为了做到这一点,我有一些JS代码:
<script src="filepicker.js"></script>
<script>
function initPicker() {
var picker = new FilePicker({
apiKey: 'MY_API_KEY',
clientId: my_client_id,
buttonEl: document.getElementById('pick'),
onSelect : function(file) {
if (file.id) {
sendLinkToBean(file.id);
} else {
alert('Unable to download file.');
}
}
});
}
</script>
<a4j:jsFunction name="sendLinkToBean" action="#{gPPersonFormBean.downloadFile()}">
<a4j:param name="param1" assignTo="#{gPPersonFormBean.fileId}"/>
</a4j:jsFunction>
的file.id到达豆,我设法得到它,如图G.Drive的API:
public void downloadFile(){
try {
Drive driveService = getDriveService();
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId) .executeMediaAndDownloadTo(outputStream);
} catch (IOException e) {
String mess = "downloadFile(): "
+ (e.getMessage()!=null?". "+e.getMessage():"")
+ (e.getCause()!=null?". "+e.getCause():"");
logger.error(mess);
}
}
但我得到FileNotFoundException:
com.google.api.client.http.HttpResponseException: 404 Not Found
{
"error": {"theID"
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "File not found: 1tvnGWDCse4TFQwIvqEDTlvv2cebfs0C2JBtjTP5A42I.",
"locationType": "parameter",
"location": "fileId"
}
],
"code": 404,
"message": "File not found: theID."
}
}
有谁知道为什么会发生这种情况? 在此先感谢。
编辑:我刚刚收到的ID与Google给出的ID与文件链接进行了比较,它们完全相同。
编辑2:如果我做driveService.files().list();
它返回一个空的列表。
谢谢您的回答,但它给了同样的错误,404文件找不到 – Aldeguer
@Aldeguer对于给您带来的不便,我深表歉意。刚才我看到了你的EDIT2。我可以问你想下载的文件是否在你的Google Drive中? – Tanaike
是的,我从Google Picker和JS制作的驱动器文档中选择它。我已经尝试了两种,一种是由我创建的文件,另一种是由同伴创建的文件,但与我共享。没有人工作 – Aldeguer