谷歌云端硬盘API为Android - 仅Drive.SCOPE_FILE访问,只需要读 [英] 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.
我已经下载了新的SDK,得到了我的应用授权等。
我使用的样本挑选与首战文件夹,然后显示内容在列表视图。
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.
如此看来新的SDK只有SCOPE_FILE访问,这是我收集只允许应用程序来看到它已经创建的文件,或那些用户选择自己。
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.
从进一步阅读,看来我必须使用REST的Java API(或其它),并认为这将让我获得甚至只读访问文件和元数据。
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.
问题是,我已经很难找到它到底是什么,我需要在Jar文件等方面,并在那里我应该把他们。
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.
我使用Android的工作室,所以可能有人告诉我:
I'm using Android Studio, so could someone tell me:
-
我需要的JAR文件完全相同
what JAR files I need exactly
我应该把它们(在libs文件夹?)
where I should put them (in libs folder?)
我需要编辑的build.gradle,包括他们?
do I need to edit build.gradle to include them?
有关授权任何例子吗?
和和示例例如列出文件和文件夹在根文件夹
and and example for listing files and folders e.g. in the ROOT folder
我需要新的SDK呢?
感谢任何帮助。
推荐答案
好吧,神该死的Java API不支持明显的的 https://www.googleapis.com/auth/drive 范围是能够访问所有文件所需。我想这样的:
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();
和结果是谷歌从API未知错误,并在日志中的异常:
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)`
我又试图另一个范围: https://www.googleapis.com/auth/drive。只读的哪个没有以不同的方式工作:
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)
试过这个在谷歌的API 7.5.0并在此智障API浪费了两个小时。我相信的Java API不能正确处理这一点,我们需要用JSON API来做到这一点。
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.
编辑:我已经找到了如何使用另一个Java API来访问谷歌驱动器本很不错的教程:的 https://developers.google.com/drive/web/quickstart/java
不幸的是,它并没有在Android上工作:
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)
在com.google.api.client.util.SecurityUtils.getJavaKeyStore(SecurityUtils.java:53)
at com.google.api.client.util.SecurityUtils.getJavaKeyStore(SecurityUtils.java:53)
爱丽丝梦游仙境的人?
这篇关于谷歌云端硬盘API为Android - 仅Drive.SCOPE_FILE访问,只需要读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!