0

我正在研究谷歌驱动器。很长一段时间后,我可以在我的帐户中的 Google 驱动器上上传文件。但是当我尝试从我的 android 应用程序访问 Google 驱动器帐户时,我无法下载文件,问题是以下方法没有解决。

Drive.Builder b = new Drive.Builder(httpTransport, jsonFactory, null);

b.setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
                    @Override
                    public void initialize(JSonHttpRequest request) throws IOException {
                        DriveRequest driveRequest = (DriveRequest) request;
                        driveRequest.setPrettyPrint(true);
                        driveRequest.setKey("186535896147");
                        driveRequest.setOauthToken(token);
                    }
                });
4

1 回答 1

0

在 Android 上,使用GoogleAccountCredential对象来授权请求​​,而不是像上面那样拦截请求。

credential = GoogleAccountCredential.usingOAuth2(context, DriveScopes.DRIVE);
b = new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();

完整流程已经在https://developers.google.com/drive/quickstart-android上实现,请作为参考。

于 2013-09-17T12:23:39.653 回答