如何为 Java 和 Google Sheets API 版本 3.0 导入 Drive API Client Library

How to import Drive API Client Library for Java and Google Sheets API version 3.0

在文档和大量论坛上苦苦挣扎了数周之后,我发现了如何将 Drive API 客户端库用于 Java 和 Google 工作表 API .我觉得特别是 android 的文档非常缺乏,所以我认为制作一个 post 来解释如何为 Android 导入 API 会很有用。这是 post 我希望我在开始使用这两个库时能找到,我希望这能帮助那些可能 运行 遇到我的问题的人..

注意:这仅适用于 Android,并且针对 Android Studio。下面描述的配置是我正在使用的配置,虽然可能包含一些不必要的文件,但它仍然有效。
所以首先,导入这两个 APIS 将提供的功能可以访问用户 Google 驱动器,并可以在该帐户上编辑 Google 电子表格。 Drive API for Android有两个"versions",一个是专门为Android and another for any Java environment. Although the one made specifically for Android is simpler to use and is better integrated with Android it has one major drawback.
Note: The Google Drive Android API currently only supports drive.file and drive.appfolder authorization scopes. If your application requires additional permissions or features not yet available in the Drive Android API, you must use the Google APIs Java Client.
This means your app can only access and edit files it has itself created, for this reason i chose to use the Google APIs Java Client. As for the Google Sheets API there are no real alternative versions, just itself.
Now the hardest time i had was trying to find out which files i needed to import, the documentation on this is hazey so here are the files needed.
Put all these files in the app\libs directory of your app.
To use Drive API Client Library for Java
First "Download the Drive API v2 Client Library for Java.制作的”在readme.html中描述了[=59=需要什么依赖].
使用以下罐子。

`google-api-client-android-1.19.1.jar (for SDK >= 2.1)
 google-http-client-android-1.19.0.jar 
 gson-2.1.jar
 protobuf-java-2.4.1.jar`


还包括 google-api-services-drive-v2-rev161-1.19.1.jar

要使用 Google Sheets API 3.0 版
here 下载 gdata 库,这包括 spreadhseet jar 和其他 gdata 库,例如地图、财务、文档、日历等。
在gdata\java\lib中使用以下文件。

`

    gdata-client-meta-1.0.jar
    gdata-core-1.0.jar
    gdata-spreadsheet-3.0.jar
    gdata-spreadsheet-meta-3.0.jar
    google-api-client-1.19.1.jar
    google-api-client-android-1.19.1.jar
    google-api-services-drive-v2-rev158-1.19.1.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
    guava-18.0.jar
    jackson-core-2.1.3.jar
    jackson-core-asl-1.9.11.jar
    jsr305.jar
    protobuf-java-2.4.1.jar
    gdata-base-1.0.jar
    gdata-client-1.0.jar

` 


下载javamail,这是专门为android`

制作的
mail.jar 
activation.jar 
activation.jar`



既然你的 app\lib 目录中有所有这些,你的 build.gradle 应该包括以下内容(自己添加):`

compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/gdata-base-1.0.jar')
compile files('libs/gdata-client-1.0.jar')
compile files('libs/gdata-client-meta-1.0.jar')
compile files('libs/gdata-core-1.0.jar')
compile files('libs/gdata-spreadsheet-3.0.jar')
compile files('libs/gdata-spreadsheet-meta-3.0.jar')
compile files('libs/google-api-client-1.19.1.jar')
compile files('libs/google-api-client-android-1.19.1.jar')
compile files('libs/google-api-services-drive-v2-rev158-1.19.1.jar')
compile files('libs/google-http-client-1.19.0.jar')
compile files('libs/google-http-client-android-1.19.0.jar')
compile files('libs/google-http-client-gson-1.19.0.jar')
compile files('libs/google-oauth-client-1.19.0.jar')
compile files('libs/gson-2.1.jar')
compile files('libs/guava-18.0.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jackson-core-asl-1.9.11.jar')
compile files('libs/jsr305.jar')
compile files('libs/mail.jar')
compile files('libs/protobuf-java-2.4.1.jar')` 


最后一步!
由于这些导入的 jar 具有大量的方法,我们需要使我们的应用程序具有多重索引,这个过程非常简单,并在 here 中进行了描述。一旦你完成了这个,你就可以开始使用驱动器和电子表格 API,如果你发现这个有用的投票让其他人可以看到!