Я использую API возобновляемой загрузки API-интерфейса Cloud Storage JSON, как указано в приведенном ниже коде.
Я настроил свой json, связанный с учетными данными, в файле bash GOOGLE_APPLICATION_CREDENTIALS = {путь json}
Когда яя пытаюсь получить доступ к API Google. Я получаю сообщение о запрете доступа с кодом 403.
Нужно ли передавать подписанный URL-адрес в функцию загрузки?
Класс RetryHttpInitializerWrapper.не могу найти, поэтому я передал HttpRequestInitializer httpRequestInitializer = null;
У меня возникла проблема из-за URL-адреса запроса, в котором я уверен.
InputStreamContent mediaContent = new InputStreamContent(contentType, stream);
mediaContent.setLength(mediaContent.getLength());
GoogleCredential credential = GoogleCredential.getApplicationDefault();
if (credential.createScopedRequired()) {
credential = credential.createScoped(StorageScopes.all());
}
Storage client = StorageOptions.getDefaultInstance().getService();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// custom HttpRequestInitializer for automatic retry upon failures.
HttpRequestInitializer httpRequestInitializer = null;
//HttpRequestInitializer httpRequestInitializer = new RetryHttpInitializerWrapper(credential);
GenericUrl requestUrl = new GenericUrl("https://www.googleapis.com/upload/storage/v1/b/"+bucket+"/o?uploadType=resumable&name="+name);
MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, httpTransport, httpRequestInitializer);
uploader.setProgressListener(new CustomProgressListener());
HttpResponse response = uploader.upload(requestUrl);
if (!response.isSuccessStatusCode()) {
throw GoogleJsonResponseException.from(JSON_FACTORY, response);
}