google-api-java-client


Source link: https://github.com/google/google-api-java-client

Google APIs Client Library for Java

Library maintenance

This client library is supported but in maintenance mode only. We are fixing necessary bugs and adding essential features to ensure this library continues to meet your needs for accessing Google APIs. Non-critical issues will be closed. Any issue may be reopened if it is causing ongoing problems.

If you're working with Google Cloud Platform APIs such as Datastore, Pub/Sub and many others, consider using the Cloud Client Libraries for Java instead. These are the new and idiomatic Java libraries targeted specifically at Google Cloud Platform Services.

Overview

The Google APIs Client Library for Java is a flexible, efficient, and powerful Java client library for accessing any HTTP-based API on the web, not just Google APIs.

The library has the following features:

Accessing Google APIs

To use Google's Java client libraries to call any Google API, you need two libraries:

  • The core Google APIs Client Library for Java (google-api-java-client), which is the generic runtime library described here. This library provides functionality common to all APIs, for example HTTP transport, error handling, authentication, JSON parsing, media download/upload, and batching.
  • An auto-generated Java library for the API you are accessing, for example the generated Java library for the BigQuery API. These generated libraries include API-specific information such as the root URL, and classes that represent entities in the context of the API. These classes are useful for making conversions between JSON objects and Java objects.

To find the generated library for a Google API, visit Google APIs Client Library for Java. The API-specific Java packages include both the core google-api-java-client and the client-specific libraries.

If you are using the old GData library, you need to migrate.

Developing for Android

If you are developing for Android and the Google API you want to use is included in the Google Play Services library, you should use that library for the best performance and experience.

To access other Google APIs, you can use the Google APIs Client Library for Java, which supports Android 1.5 (or higher).

Other Java environments

In addition to Android 1.5 or higher, the Google APIs Client Library for Java supports the following Java environments:

Not supported: Google Web Toolkit (GWT), Java mobile (ME), and Java 1.4 (or earlier).

Highlighted Features

  • The library makes it simple to call Google APIs.

You can call Google APIs using Google service-specific generated libraries with the Google APIs Client Library for Java. Here's an example that makes a call to the Google Calendar API:

// Show events on user's calendar. View.header("Show Calendars");
 CalendarList feed = client.calendarList().list().execute();
 View.display(feed);
 
  • The library makes authentication easier.

The authentication library can reduce the amount of code needed to handle OAuth 2.0, and sometimes a few lines is all you need. For example:

/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception {

// load client secrets
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,

 new InputStreamReader(CalendarSample.class.getResourceAsStream("/client_secrets.json")));

// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(

 httpTransport, JSON_FACTORY, clientSecrets,

 Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory)

 .build();

// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
 
}
 
  • The library makes batching and media upload/download easier.

The library offers helper classes for batching, media upload, and media download.

  • The library runs on Google App Engine.

App Engine-specific helpers make quick work of authenticated calls to APIs, and you do not need to worry about exchanging code for tokens. For example:

@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

AppIdentityCredential credential =

 new AppIdentityCredential(Arrays.asList(UrlshortenerScopes.URLSHORTENER));

Urlshortener shortener =

 new Urlshortener.Builder(new UrlFetchTransport(), new JacksonFactory(), credential)

 .build();

UrlHistory history = shortener.URL().list().execute();

... 
}
 

If you are developing for Android and the Google API you want to use is included in the Google Play Services library, you should use that library for the best performance and experience.

To access other Google APIs, you can use the Google Client Library for Java's Android-specific helper classes, which are are well-integrated with Android AccountManager. For example:

@Override public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// Google Accounts
credential =

 GoogleAccountCredential.usingOAuth2(this, Collections.singleton(TasksScopes.TASKS));

SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);

credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));

// Tasks client
service =

 new com.google.api.services.tasks.Tasks.Builder(httpTransport, jsonFactory, credential)

  .setApplicationName("Google-TasksAndroidSample/1.0").build();
 
}
 
  • The library is easy to install.

The Google APIs Client Library for Java is easy to install, and you can download the binary directly from the Downloads page, or you can use Maven or Gradle. To use Maven, add the following lines to your pom.xml file:

```maven <project>
<dependencies>
  <dependency>

 <groupId>com.google.api-client</groupId>

 <artifactId>google-api-client</artifactId>

 <version>1.23.0</version>
  </dependency>
</dependencies> </project>  ```  

To use Gradle, add the following lines to your build.gradle file:

repositories {

  mavenCentral() 
}
 dependencies {

  compile 'com.google.api-client:google-api-client:1.23.0' 
}

Dependencies

This library is built on top of two common libraries, also built by Google, and also designed to work with any HTTP service on the web:

Important Warnings

@Beta

Features marked with the @Beta annotation at the class or method level are subject to change. They might be modified in any way, or even removed, in any major release. You should not use beta features if your code is a library itself (that is, if your code is used on the CLASSPATH of users outside your own control).

Deprecations

Deprecated non-beta features will be removed eighteen months after the release in which they are first deprecated. You must fix your usages before this time. If you don't, any type of breakage might result, and you are not guaranteed a compilation error.

Documentation

Links

Resources

android-schema-utils is an Android library for simplifying database schema and migrations management.

This is a repository with real-world useful examples of using RxJava with Android.

This is the DeployGate plugin for Apache Maven.

In-memory immutable 2D R-tree implementation in java using RxJava Observables for reactive processing of search results.

This library provides a means to access the content on the Web easily from AndroidWear.

Bash script to simplify adb command usage.

This is a helpful bash utility for working with multiple devices at the same time.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes