Questions tagged [google-api-java-client]

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.

Google APIs Client Library for Java

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: - Java 5 (or higher), standard (SE) and enterprise (EE) - Google App Engine

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:

    java // 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:

    java /** 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:

    java @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(); ... }

  • The library runs on Android (@Beta).

    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:

    java @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.20.0</version> </dependency> </dependencies> </project>

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

    gradle repositories { mavenCentral() } dependencies { compile 'com.google.api-client:google-api-client:1.20.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: * Google HTTP Client Library for Java * Google OAuth Client Library for Java

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

1147 questions
3
votes
1 answer

Spring Boot: No converter for [class java.io.ByteArrayOutputStream]

I'm trying to export a document from Google Drive via their Drive API, and there's an example of it in the docs, but I didn't have any luck with it. Here's my code: @RequestMapping(value = "/test", method = RequestMethod.GET, produces =…
3
votes
1 answer

Is there some way to include multiple Google API services (e.g. Sheets and Docs) for a single Java project?

I'm using Google's API services for the first time for a personal Java project involving reading data from a Google Sheet and writing information relating to it to a separate Google Doc. I've used Google's Quickstart Guides for both listed here and…
3
votes
2 answers

Error while creating google calendar event with a service account

I have a requirement of creating a google calendar event on a calendar and add other users as attendees to that event. The objective is to send calendar events to the application users without taking their consent ( O-Auth ). After reading Google's…
3
votes
1 answer

Google calendar event, conference details are not being set

I'm trying to create the Google Calendar event with the conference(Google Meet) using Java SDK V3. The event is getting created but the conference details are not being set. Not sure what's missing Create request: Calendar service = new Calendar …
3
votes
1 answer

Google Service Account no longer has access to Calendar API

I had a react app working perfectly using gapi-script to retrieve Google Calendar events. It was working until recently. Now I get a 404 "Not Found" error when trying to authenticate. I assume something may have changed in the API or authentication…
3
votes
1 answer

Google Drive API throwing userRateLimitExceeded and then dailyLimitExceededUnreg

I'm using google drive API to fetch a few thousand documents. The credentials I'm using to connect are using the setServiceAccount and setServiceAccountPrivateKey. When I start making requests - I'll receive the following after a short period of…
3
votes
1 answer

Google maps DirectionApi : FATAL EXCEPTION: Rate Limited Dispatcher

description: I want to get result from direction api using Java Client for Google Maps Services.But when i click onInfoWindoclickthen i got FATAL EXCEPTION: Rate Limited Dispatcher error on my android studio.Please anyone help me.I try solve this…
3
votes
1 answer

How can I upload files to a folder in Google Team Drive with a service account credential?

I'm trying to implement a new service to our application using Google Drive Java API v3 that is responsible for uploading files to a specific folder in Google Team Drive. I use the service account that my company has created specifically for this…
3
votes
1 answer

How are Google Drive API request quotas calculated? 'userRateLimitExceeded' being triggered when below known quotas

Currently integrating a project with Google Drive using the Drive API Client Library for Java, when using a Service Account to impersonate a user to retrieve its Drive contents, userRateLimitExceeded is triggered when the number of reported requests…
3
votes
0 answers

Google Cloud app -Android- restriction on API key does not work

I'm using an API key for some Google Cloud services but the problem is the following: if I use the "app restriction" displayed in the Google Cloud console, my Android application losses access, and Logcat says "error 403", which means "not…
3
votes
2 answers

Google Cloud Storage SDK(Java) randomly calling IP addersses instead of covering that call with google domain

I'm using Google Storage SDK to download and upload files in Google bucket. I have also whitelisted .googleapis.com and *.google.com domains. But some of the calls from SDK are calling IP address(Owned by Google) directly like https://216.58.220.10…
3
votes
1 answer

Is Google Sheets API's Sheets automatically updated

I have a thread containing an infinite loop that should always be looking at the most recent version of a Google Sheet. How much to recreate each iteration to ensure that my reference to it is updated? The NetHttpTransport? The Sheets object? The…
3
votes
2 answers

Invalid delegate for mailbox in Gmail API

I am trying to get the Delegates for a mailbox using Gmail API. My application is running on Google App-engine and has the feature of Add, Remove,Get Delegates using Email Setting API. Now I am planning to migrate these features to Gmail API since…
3
votes
0 answers

Publisher API without oAuth of developer account

I have some doubts. I stuck in that for a week. I am doing an app to get all reviews from a play store. It's for all end user who has an account in play store. https://developers.google.com/android-publisher/getting_started This document specifies…
3
votes
1 answer

How to access google developer api in android app

I am trying to develop an app which needs to access google developer API by using developer email.I have gone through official documentation.I don't understand much.I created client id by following this…