Skip to content Skip to sidebar Skip to footer

Google Drive Api For Android - Only Drive.scope_file Access, Need Read Only

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 fol

Solution 1:

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-3014:11:48.8033023-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-3014:12:25.0823023-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?

Post a Comment for "Google Drive Api For Android - Only Drive.scope_file Access, Need Read Only"