Android 获得;302临时搬迁;使用驱动器SDK从Google Drive下载文件时

Android 获得;302临时搬迁;使用驱动器SDK从Google Drive下载文件时,android,google-drive-api,Android,Google Drive Api,我试图在Android上的GoogleDrive中下载文件,我遵循的是 但是得到错误302:有人知道这里发生了什么吗 03-29 14:56:07.316 E/XXGoogleDrive(25539): [25566][DriveDLFutureTask] [getInputStream]com.google.api.client.http.HttpResponseException: **302 Moved Temporarily** 03-29 14:56:07.326 W/System.e

我试图在Android上的GoogleDrive中下载文件,我遵循的是

但是得到错误302:有人知道这里发生了什么吗

03-29 14:56:07.316 E/XXGoogleDrive(25539): [25566][DriveDLFutureTask] [getInputStream]com.google.api.client.http.HttpResponseException: **302 Moved Temporarily**
03-29 14:56:07.326 W/System.err(25539): com.google.api.client.http.HttpResponseException: 302 Moved Temporarily
03-29 14:56:07.326 W/System.err(25539):     at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1062)

发生“暂时移动”是因为该页正在尝试重新定向到用户身份验证页,或在文件大小超过25 MB时进行病毒扫描

我通过使用带有'alt=media'查询参数的文件获取请求使其工作,工作代码如下

private static byte[] getBytes(Drive drive, String accessToken, String fileId, long position, long byteCount) {
        byte[] receivedByteArray = null;
        String downloadUrl = "https://www.googleapis.com/drive/v3/files/" + fileId + "?alt=media&access_token="
                + accessToken;
        if (downloadUrl != null && downloadUrl.length() > 0) {
            try {
                com.google.api.client.http.HttpRequest httpRequestGet = drive.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl));
                httpRequestGet.getHeaders().setRange("bytes=" + position + "-" + (position + byteCount - 1));
                com.google.api.client.http.HttpResponse response = httpRequestGet.execute();
                InputStream is = response.getContent();
                receivedByteArray = IOUtils.toByteArray(is);
                response.disconnect();
                System.out.println("google-http-client-1.18.0-rc response: [" + position + ", " + (position + receivedByteArray.length - 1) + "]");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return receivedByteArray;
    }

即使我面临错误,你能找到解决方案吗?
private static byte[] getBytes(Drive drive, String accessToken, String fileId, long position, long byteCount) {
        byte[] receivedByteArray = null;
        String downloadUrl = "https://www.googleapis.com/drive/v3/files/" + fileId + "?alt=media&access_token="
                + accessToken;
        if (downloadUrl != null && downloadUrl.length() > 0) {
            try {
                com.google.api.client.http.HttpRequest httpRequestGet = drive.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl));
                httpRequestGet.getHeaders().setRange("bytes=" + position + "-" + (position + byteCount - 1));
                com.google.api.client.http.HttpResponse response = httpRequestGet.execute();
                InputStream is = response.getContent();
                receivedByteArray = IOUtils.toByteArray(is);
                response.disconnect();
                System.out.println("google-http-client-1.18.0-rc response: [" + position + ", " + (position + receivedByteArray.length - 1) + "]");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return receivedByteArray;
    }