问题
I'd like for my app to be able to read from a pre-defined shared public Google Drive folder without the user having to log in or choose a Google account.
Background / Environment
Using my desktop browser, I have created a public folder on my Google Drive that is set up to be public. Anyone with the link may access (read) the drive, so no authorization is required:
In my Android Studio project, I have gone into File > Project Structure > Dependencies
and added com.google.android.gms:play-services-drive:10.2.0
I now have the ability to create a new GoogleApiClient.Builder()
.
Question
I have looked at various examples, but in most cases, the drive has been created by the Android application. This is not the situation I'm trying to manage.
This question is about accessing a drive that has been made public using the "folder ID" or whatever you call 0B6X74x23H....
that was assigned when the folder was originally shared and made public.
I have examined the demo code provided by Google, but that, presumably, is not for a public folder because it says:
...need to register an OAuth 2.0 client
At a minimum, I could drive the process by using http-client, going to the sharing link https://drive.google.com/drive/folders/0B6X74x23Hx7DNE13M0ZIbVI....?usp=sharing
with no authentication and not need to jump through hoops. But of course it would be cleaner to use a defined API and simply specify the public shared folder in order to list the contents and, if needed, download the files from the public folder.
When I try this code:
Scope publicFolder = new Scope(EXISTING_FOLDER_ID);
mGoogleApiClient = new GoogleApiClient.Builder(mActivity)
.addApi(Drive.API)
.addScope(publicFolder)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
This method fires:
GoogleApiClient.OnConnectionFailedListener.onConnectionFailed()
The result contains statusCode=SIGN_IN_REQUIRED
. But of course sign-in is NOT required for a folder that's public.
来源:https://stackoverflow.com/questions/44143307/accessing-public-google-drive-folder-from-android-app-without-authenticating