授权我的应用程序中使用现有的文件夹我的、应用程序、文件夹

2023-09-06 03:35:08 作者:幻想,灵感的影子

采用的是Android驱动的API,尝试使用连接时:

Using the Android Drive API, when trying to connect using:

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Drive.API).addScope(Drive.SCOPE_FILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).build();

getGoogleApiClient.connect();

我得到的选择一个帐户屏幕,选择帐户后,我看到这样的:

I get the select an account screen and after selecting an account, I see this:

查看和管理您已打开或创建谷歌驱动器文件   与此应用程序

View and manage Google Drive files that you have opened or created with this app

如果我是什么来访问其他应用程序创建的文件?

What if I what to access files created by other apps?

有没有办法为我的应用程序,要求特定文件夹的权限?

Is there a way for my application to ask for authorization of a specific folder?

推荐答案

谷歌播放服务客户端库 提供了一个Android开发者的API与个体谷歌服务的无缝集成。

Google Play Services client library provides an Android developer with APIs for seamless integration with the individual Google services.

该库还让你的应用程序提供一致的用户界面,以获得用户的授权与他们的凭据访问这些服务。

The library also let your apps offers a consistent user interface to obtain authorization from users to access these services with their credentials.

访问谷歌驱动器服务

谷歌Play业务客户端库附带 谷歌推动Android API ,提供了访问到谷歌驱动器的服务。

Google Play services client library ships with Google Drive Android API that provides access to the Google Drive service.

不过,谷歌推动Android API目前仅提供的 drive.file 和 drive.appfolder 的的 这在某种程度上是有限的,如果您的应用程序需要访问所有内容的用户的驱动器上的授权范围。

However, Google Drive Android API currently offers only drive.file and drive.appfolder authorization scopes which are limited in a way if your app needs access to all the contents on the user's drive.

要提供驱动范围,您将需要使用的REST API提供的 驱动器的API客户端库的Java 。这个库对 谷歌的API客户端库的Java ,提供了一个依赖生成的客户端库从任何应用程序访问使用的REST API个别谷歌服务(网络,安装或Android)

To provide drive scope, you will need to use REST APIs offered by Drive API Client Library for Java. This library has a dependency on Google APIs Client Library for Java that offers generated client libs for access to individual Google services using REST APIs from any application (web, installed or Android)

下载的驱动API第2版客户端库对Java 。 libs文件夹包含所有的全球适用的依赖关系(谷歌的API客户端库用于Java),你可能需要在所有类型的应用程序(网络,安装或Android应用程序)。

Download the Drive API v2 Client Library for Java. The libs folder contains all the globally-applicable dependencies (Google APIs Client Library for Java) you might need across all application types (web, installed, or Android application).

有关Android的,你需要以下jar文件(如驱动器/ readme.html文件中所述)的依赖关系理清

For Android, you will need the following jars (as described in drive/readme.html) to sort out the dependencies

google-api-services-drive-v2-rev143-1.19.0.jar
google-api-client-1.19.0.jar
google-api-client-android-1.19.0.jar
google-http-client-1.19.0.jar
google-http-client-android-1.19.0.jar
google-http-client-gson-1.19.0.jar
google-oauth-client-1.19.0.jar
gson-2.1.jar
jsr305-1.3.9.jar

授权

在访问谷歌驱动器(或任何其他谷歌)的服务,您必须授权的应用程序(使用OAuth 2.0)

Before accessing Google Drive (or any other Google) service, you need to authorize your application (using OAuth 2.0)

有关使用的谷歌播放服务客户端库的,这将是由GoogleApiClient. hm vnisedit下载 VNISEdit NSIS脚本代码的一个编辑器 下载 v2.0.3 简体中文版

For applications using Google Play Services client library, this will be handled by GoogleApiClient.

不过,如果你想使用该服务/谷歌API不包含在谷歌Play业务库的,你可以连接使用相应的REST API手动发出请求或使用客户端库由服务提供商提供的,但是你必须获取的OAuth 2.0令牌。

However, if the service/Google API you want to use is not included in the Google Play services library, you can connect using the appropriate REST API to manually make requests or using a client library provided by the service provider, but you must obtain an OAuth 2.0 token.

有关的驱动器的范围内,你需要使用的谷歌的API客户端库的Java 的,生成的客户端库(车程V2,在我们的例子)。要获得授权令牌,您可以 -

For drive scope, you need to use Google APIs Client Library for Java and the generated client libraries (drive v2, in our case). To obtain an authorization token, you can either -

直接使用的OAuth 2.0 库从谷歌的API客户端库的Java 的(不pferred为Android $ P $) 或利用谷歌Play业务库的使用授权部分GoogleAuthUtil和AccountPicker。 阅读与谷歌的授权的REST API 。 (GoogleAuthUtil.getToken()缓存和管理令牌到期,并刷新自己。但是,如果网络错误/服务器的负载,可能需要重试前使用指数退避算法进行标记,以便以不淹没服务器的请求请参考3) 或GoogleAccountCredential在谷歌-API的客户端Android的1.19.0.jar附带的谷歌的API客户端库为Java定义的的。该软件包提供基于谷歌Play业务和GoogleAccountCredential只是一个包装的周围的 GoogleAuthUtil 和 AccountPicker 的。这将允许您使用相同一致的授权流程,并附带谷歌Play业务客户端库,同时委派令牌管理和使用指数退避策略(如上所述)标准的账户选择器用户界面GoogleAccountCredential。请参阅 1 一个例子。 directly use the OAuth 2.0 library from Google APIs Client Library for Java (not preferred for android) or leverage the authorization portion of the Google Play services library using GoogleAuthUtil and AccountPicker. Read Authorizing with Google for REST APIs. (GoogleAuthUtil.getToken() caches and manages token expiry and refresh itself. However, in case of network errors/server load, you might need to use an exponential back-off algorithm before retrying for the token so to not flood the server with requests. Refer 3) or use the GoogleAccountCredential defined in google-api-client-android-1.19.0.jar that comes with Google APIs Client Library for Java. The package offers Utilities based on Google Play services and GoogleAccountCredential is just a wrapper around GoogleAuthUtil and AccountPicker. This would allow you to use the same consistent authorization flow and the standard account picker UI that comes with Google Play services client library while delegating the token management and using an exponential back-off strategy (as noted above) to GoogleAccountCredential. Refer 1 for an example.

请注意,随着最后两个方法,您同时使用的谷歌Play业务客户端库的(对于许可)和谷歌的API客户端库的Java 以及驱动API第2版客户端库的Java 的(对于访问以谷歌驱动器与服务的驱动器的认证范围)。

Note that with the last two approaches, you are using both Google Play services client libraries (for authorization) and Google APIs Client Library for Java along with Drive API v2 Client Library for Java (for access to Google Drive service with drive authentication scope).

包引用

谷歌播放服务客户端库 驱动的API客户端库对Java 谷歌的API客户端库对Java 1.19.0 Google Play Services client library Drive API Client Library for Java Google API Client Library for Java 1.19.0

此外结帐 -

http://www.techsfo.com/blog/2014/03/android-$p$pparing-to-access-google-drive-with-an-app-part-1/ http://developer.samsung.com/android/technical-docs/Using-Google-APIs 谷歌Play业务和OAuth的身份工具 http://www.techsfo.com/blog/2014/03/android-preparing-to-access-google-drive-with-an-app-part-1/ http://developer.samsung.com/android/technical-docs/Using-Google-APIs Google Play services and OAuth Identity Tools

这答案也贴在我的博客here.

This answer also posted at my blog here.