您可以下載 Java 適用的 Google OAuth 用戶端程式庫及其依附元件,也可以使用 Maven。
另請參閱 Google HTTP Client Library for Java 說明文件中的 ProGuard 設定說明。
下載含有依附元件的程式庫
請下載最新的 ZIP 檔案,您可以在下載頁面上找到該檔案,並在電腦上解壓縮。這個 ZIP 檔案包含用戶端程式庫類別的 jar 檔案,以及每個成果及其依附元件的關聯來源 jar 檔案。您可以在「dependencies」資料夾中,找到不同程式庫的依附元件圖表和授權。如要進一步瞭解下載內容,請參閱 readme.html 檔案。
Android
如果您是為 Android 開發應用程式,且您要使用的 Google API 已納入 Google Play 服務程式庫,請使用 Google Play 服務程式庫,以獲得最佳效能和體驗。
如要在 Android 上使用 Java 適用的 Google OAuth 用戶端程式庫,請務必瞭解哪些依附元件與 Android 相容,特別是 Android SDK 級別。Android 應用程式需要 libs 資料夾中的 jar 檔案或較新的相容版本:
google-oauth-client-1.30.4.jar
google-http-client-1.32.1.jar
google-http-client-android-1.32.1jar
gson-2.8.5.jar
jackson-core-2.9.5.jar
jsr305-3.0.2.jar
protobuf-java-3.6.1.jar
Google App Engine
Google App Engine 應用程式需要下列 jar 檔案,或 libs 資料夾中的新版相容版本:
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThe Google OAuth Client Library for Java can be downloaded as a zip file or accessed using Maven.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can utilize the Google Play Services library for optimal performance in Android applications when applicable.\u003c/p\u003e\n"],["\u003cp\u003eSpecific jar files are needed for compatibility with Android, Google App Engine, Servlet applications, and Generic Java applications.\u003c/p\u003e\n"],["\u003cp\u003eThe library is divided into five modules: google-oauth-client, google-oauth-client-servlet, google-oauth-client-appengine, google-oauth-client-java6, and google-oauth-client-jetty, each with their Maven dependencies.\u003c/p\u003e\n"],["\u003cp\u003eThe google-oauth-client module is compatible with all supported Java platforms, including Android, but Android users need to exclude unused dependencies to prevent conflicts.\u003c/p\u003e\n"]]],[],null,["# Setup Instructions\n\nYou can download the Google OAuth Client Library for Java and its dependencies in\na zip file, or you can use Maven.\n\nAlso see the\n[ProGuard setup instructions](/api-client-library/java/google-http-java-client/setup#proguard)\nthat are part of the Google HTTP Client Library for Java documentation.\n\nDownload the library with dependencies\n--------------------------------------\n\nDownload the latest zip file, which you can find on the\n[downloads page](/api-client-library/java/google-oauth-java-client/download),\nand extract it on your computer. This zip file contains the client library class\njar files and the associated source jar files for each artifact and their\ndependencies. You can find dependency graphs and licenses for the different\nlibraries in the dependencies folder. For more details about the contents of the\ndownload, see the readme.html file.\n\n### Android\n\nIf you are developing for Android, and the Google API you want to use is\nincluded in the\n[Google Play Services library](https://developer.android.com/google/play-services/index.html),\nuse the Google Play Services library for the best performance and experience.\n\nIf you are using the Google OAuth Client Library for Java with Android, it is\nimportant to know which dependencies are compatible with Android, specifically\nwhich Android SDK level. Android applications require the following jar files, or\nnewer compatible versions, from the libs folder:\n\n- google-oauth-client-1.30.4.jar\n- google-http-client-1.32.1.jar\n- google-http-client-android-1.32.1jar\n- gson-2.8.5.jar\n- jackson-core-2.9.5.jar\n- jsr305-3.0.2.jar\n- protobuf-java-3.6.1.jar\n\n| **Warning:** For Android, you MUST place the jar files in a directory named \"libs\" so that the APK packager can find them. Otherwise, you will get a `NoClassDefFoundError` error at runtime.\n\n### Google App Engine\n\nGoogle App Engine applications require the following jar files, or newer\ncompatible versions, from the libs folder:\n\n- google-oauth-client-1.30.4.jar\n- google-oauth-client-appengine-1.30.4.jar\n- google-oauth-client-servlet-1.30.4.jar\n- google-http-client-1.32.1.jar\n- google-http-client-appengine-1.32.1.jar\n- gson-2.8.5.jar\n- jackson-core-2.9.5.jar\n- jsr305-3.0.2.jar\n- protobuf-java-3.6.1.jar\n- transaction-api-1.1.jar\n- xpp3-1.1.4c.jar\n\n### Servlet\n\nServlet applications require the following jar files, or newer compatible\nversions, from the libs folder:\n\n- google-oauth-client-1.30.4.jar\n- google-oauth-client-servlet-1.32.1.jar\n- google-http-client-1.32.1.jar\n- commons-logging-1.2.0.jar\n- gson-2.8.5.jar\n- jackson-core-2.9.5.jar\n- httpclient-4.5.9.jar\n- httpcore-4.4.11.jar\n- jackson-core-2.1.3.jar\n- jdo2-api-2.3-eb.jar\n- jsr305-3.0.2.jar\n- protobuf-java-3.6.1.jar\n- transaction-api-1.1.jar\n- xpp3-1.1.4c.jar\n\n### Generic Java\n\nGeneral purpose Java applications require the following jar files, or newer\ncompatible versions, from the libs folder:\n\n- google-oauth-client-1.30.4.jar\n- google-http-client-1.32.1.jar\n- commons-logging-1.2.0.jar\n- gson-2.8.5.jar\n- jackson-core-2.9.5.jar\n- httpclient-4.5.9.jar\n- httpcore-4.4.11.jar\n- jsr305-3.0.2.jar\n- protobuf-java-3.6.1.jar\n- xpp3-1.1.4c.jar\n\nMaven\n-----\n\nThe Google OAuth Client Library for Java is in the central\n[Maven](http://maven.apache.org) repository. The Maven `groupId` for all artifacts\nfor this library is `com.google.oauth-client`. Specific Maven instructions are given\nfor each module (below).\n\nModules\n-------\n\nThis library is composed of five modules:\n\n- [google-oauth-client](#google-oauth-client)\n- [google-oauth-client-servlet](#google-oauth-client-servlet)\n- [google-oauth-client-appengine](#google-oauth-client-appengine)\n- [google-oauth-client-java6](#google-oauth-client-java6)\n- [google-oauth-client-jetty](#google-oauth-client-jetty)\n\n### google-oauth-client\n\nGoogle OAuth Client Library for Java (google-oauth-client) is designed to be\ncompatible with all supported Java platforms, including Android.\n\nMaven usage: \n\n```java\n\u003cdependency\u003e\n \u003cgroupId\u003ecom.google.oauth-client\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-oauth-client\u003c/artifactId\u003e\n \u003cversion\u003e1.30.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nOn Android, you will need to explicitly exclude unused dependencies: \n\n```java\n\u003cdependency\u003e\n \u003cgroupId\u003ecom.google.oauth-client\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-oauth-client\u003c/artifactId\u003e\n \u003cversion\u003e1.30.4\u003c/version\u003e\n \u003cexclusions\u003e\n \u003cexclusion\u003e\n \u003cartifactId\u003expp3\u003c/artifactId\u003e\n \u003cgroupId\u003expp3\u003c/groupId\u003e\n \u003c/exclusion\u003e\n \u003cexclusion\u003e\n \u003cartifactId\u003ehttpclient\u003c/artifactId\u003e\n \u003cgroupId\u003eorg.apache.httpcomponents\u003c/groupId\u003e\n \u003c/exclusion\u003e\n \u003cexclusion\u003e\n \u003cartifactId\u003ejunit\u003c/artifactId\u003e\n \u003cgroupId\u003ejunit\u003c/groupId\u003e\n \u003c/exclusion\u003e\n \u003cexclusion\u003e\n \u003cartifactId\u003eandroid\u003c/artifactId\u003e\n \u003cgroupId\u003ecom.google.android\u003c/groupId\u003e\n \u003c/exclusion\u003e\n \u003c/exclusions\u003e\n\u003c/dependency\u003e\n```\n\n### google-oauth-client-servlet\n\nServlet and JDO extensions to the Google OAuth Client Library for Java\n(google-oauth-client-servlet) support Java servlet web applications. This module\ndepends on google-oauth-client.\n\nMaven usage: \n\n```java\n\u003cdependency\u003e\n \u003cgroupId\u003ecom.google.oauth-client\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-oauth-client-servlet\u003c/artifactId\u003e\n \u003cversion\u003e1.30.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### google-oauth-client-appengine\n\nGoogle App Engine extensions to the Google OAuth Client Library for Java\n(google-oauth-client-appengine) support Java Google App Engine applications. This\nmodule depends on google-oauth-client and google-oauth-client-servlet.\n\nMaven usage: \n\n```java\n\u003cdependency\u003e\n \u003cgroupId\u003ecom.google.oauth-client\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-oauth-client-appengine\u003c/artifactId\u003e\n \u003cversion\u003e1.30.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### google-oauth-client-java6\n\nJava 6 (and higher) extensions to the Google OAuth Client Library for Java\n(google-oauth-client-java6) support Java6+ applications. This module depends on\ngoogle-oauth-client.\n\nMaven usage: \n\n```java\n\u003cdependency\u003e\n \u003cgroupId\u003ecom.google.oauth-client\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-oauth-client-java6\u003c/artifactId\u003e\n \u003cversion\u003e1.30.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### google-oauth-client-jetty\n\nJetty extensions to the Google OAuth Client Library for Java\n(google-oauth-client-jetty) support authorization code flow for installed\napplications. This module depends on google-oauth-client-java6.\n\nMaven usage: \n\n```java\n\u003cdependency\u003e\n \u003cgroupId\u003ecom.google.oauth-client\u003c/groupId\u003e\n \u003cartifactId\u003egoogle-oauth-client-jetty\u003c/artifactId\u003e\n \u003cversion\u003e1.30.4\u003c/version\u003e\n\u003c/dependency\u003e\n```"]]