问题
I am trying to use this:
https://developers.google.com/drive/android/get-started
Which is the Google drive SDK for Android.
I want to be able to list all files in a users Google drive account. But only access is given to files and folders that the app created (or that the user selects).
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Can Google Devs tell me if it is possible to List a users files and folders with this SDK, and retrieve metadata? Only SCOPE_FILE access is permitted.
If not, will more access be given in the future?
I have tried (and failed miserably) to use the Java Library but I cannot get it to work. So hopefully I can find out of the new SDK will include other permissions (which the Java library does).
Thanks
回答1:
My solution is use google-http-java-client library and google-api-client library instead of google drive SDK for Android. The main benefit is that you can access all the files on the Google drive. below is a section code to create the Drive object in code, then you can use this object to access the files.
final GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport).setJsonFactory(jsonFactory)
.addRefreshListener(refreshListener)
.setClientSecrets(clientId, clientSecret).build()
.setRefreshToken(refreshToken).setAccessToken(accessToken);
// Create a new authorized API client
final Drive drive = new Drive.Builder(httpTransport, jsonFactory,
credential).build();
回答2:
As you saw, currently only SCOPE_FILE is available on Android. Users much prefer that you have this scope, so that they can control which files your app accesses. You should be able to use the provided user interfaces to allow your users to browse all of the files and pick the one they want to use with your app. See OpenFileActivity.
来源:https://stackoverflow.com/questions/23341776/google-drive-sdk-drive-scopes