I try to use google drive api v3 to download file in java with this code i get it from github from this link this link of java file in github
package drive.sample;
import ...
public class MainActivity extends AppCompatActivity {
private static ByteArrayOutputStream downloadFile(String realFileId) throws IOException{
/* Load pre-authorized user credentials from the environment.
TODO(developer) - See https://developers.google.com/identity for
guides on implementing OAuth2 for your application.*/
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Arrays.asList(DriveScopes.DRIVE_FILE));
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
credentials);
// Build a new authorized API client service.
Drive service = new Drive.Builder(new NetHttpTransport(),
GsonFactory.getDefaultInstance(),
requestInitializer)
.setApplicationName("Drive samples")
.build();
try {
OutputStream outputStream = new ByteArrayOutputStream();
service.files().get(realFileId)
.executeMediaAndDownloadTo(outputStream);
return (ByteArrayOutputStream) outputStream;
}catch (GoogleJsonResponseException e) {
// TODO(developer) - handle error appropriately
System.err.println("Unable to move file: " + e.getDetails());
throw e;
}
}
}
// [END drive_download_file]
But when run app it show me this error
Error : type of HttpCredentialsAdapter (com. google . auth.Credentials) is erroneous
How i can solve this problem ?