So I'm a bit of a novice and I wish to list all the files and folders in Google Drive.
I had downloaded the new SDK, got my app all authorised etc. I used the samples to pick a folder with an opener, and then display the contents in the Listview.
BUT - NO files were displayed. It only displays any sub folders from the selected folder.
So it seems the new SDK only has SCOPE_FILE access, which I gather only allows the app to see files that it has created, or ones that the user selects themselves.
But since I need to be able to list all files and folders in a given folder, then this doesn't work for me at all.
From further reading, it seems I have to use the REST Java API (or something), and that this will allow me to get even read-only access to files and metadata.
Problem is, I have having trouble finding what exactly it is I need in terms of Jar files etc, and where I should put them.
Remember, I'm new to all this.
I'm using Android Studio, so could someone tell me:
what JAR files I need exactly
where I should put them (in libs folder?)
do I need to edit build.gradle to include them?
any example for authorizing?
and and example for listing files and folders e.g. in the ROOT folder
do I need the new SDK at all?
Thanks for any help with this.
Okay, the god-damn Java API does not apparently support the https://www.googleapis.com/auth/drive scope which is needed to access all files. I tried this:
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(new Scope("https://www.googleapis.com/auth/drive"))
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
And the result is "Unknown error from Google API" and an exception in logs:
06-30 14:11:48.803 3023-29855/? E/ClientConnectionOperation﹕ Handling authorization failure
com.google.android.gms.drive.auth.c: Authorization failed: Unsupported scope: https://www.googleapis.com/auth/drive
at com.google.android.gms.drive.auth.g.a(SourceFile:77)
at com.google.android.gms.drive.api.g.<init>(SourceFile:226)
at com.google.android.gms.drive.api.a.k.a(SourceFile:46)
at com.google.android.gms.common.service.g.run(SourceFile:178)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)`
I then tried another scope: https://www.googleapis.com/auth/drive.readonly Which did not work in a different way:
06-30 14:12:25.082 3023-29981/? E/ClientConnectionOperation﹕ Handling authorization failure
com.google.android.gms.drive.auth.c: Authorization failed: No valid Drive authorization scope provided.
at com.google.android.gms.drive.auth.g.a(SourceFile:87)
at com.google.android.gms.drive.api.g.<init>(SourceFile:226)
at com.google.android.gms.drive.api.a.k.a(SourceFile:46)
at com.google.android.gms.common.service.g.run(SourceFile:178)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Tried this on Google APIs 7.5.0 and wasted two hours on this retarded API. I believe the Java API can't handle this correctly and we will need to do this with the JSON API.
Edit: I have found this very nice tutorial on how to use another Java API to access Google Drive: https://developers.google.com/drive/web/quickstart/java Unfortunately, it does not work on Android:
Caused by: java.security.NoSuchAlgorithmException: KeyStore JKS implementation not found
at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:190)
at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:139)
at java.security.KeyStore.getInstance(KeyStore.java:116)
at com.google.api.client.util.SecurityUtils.getJavaKeyStore(SecurityUtils.java:53)
Alice in Wonderland anyone?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With