How to set up Google Calendar Java

I follow the Google instructions for a step-by-step guide, but for some reason I can’t find the few packages that I need to import. Packages that my application cannot find (or lines referenced by my IDE):

import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl; 

I can't seem to find the banks that hold them. My classpath contains:

 //The Google Calendar Client API: google-api-services-calendar-v3-rev16-1.8.0-beta.jar //And of course the Google API Core: commons-logging-1.1.1.jar google-api-client-1.11.0-beta.jar google-api-client-1.11.0-beta.jar.properties google-api-client-android-1.11.0-beta.jar google-api-client-android-1.11.0-beta.jar.properties google-api-client-android2-1.11.0-beta.jar google-api-client-android2-1.11.0-beta.jar.properties google-api-client-appengine-1.11.0-beta.jar google-api-client-java6-1.11.0-beta.jar google-http-client-1.11.0-beta.jar google-http-client-1.11.0-beta.jar.properties google-http-client-android-1.11.0-beta.jar google-http-client-android-1.11.0-beta.jar.properties google-http-client-android2-1.11.0-beta.jar google-http-client-android2-1.11.0-beta.jar.properties google-http-client-android3-1.11.0-beta.jar google-http-client-android3-1.11.0-beta.jar.properties google-http-client-appengine-1.11.0-beta.jar google-http-client-gson-1.11.0-beta.jar google-http-client-gson-1.11.0-beta.jar.properties google-http-client-jackson-1.11.0-beta.jar google-http-client-jackson-1.11.0-beta.jar.properties google-http-client-jackson2-1.11.0-beta.jar google-http-client-jackson2-1.11.0-beta.jar.properties google-oauth-client-1.11.0-beta.jar google-oauth-client-1.11.0-beta.jar.properties google-oauth-client-appengine-1.11.0-beta.jar google-oauth-client-java6-1.11.0-beta.jar google-oauth-client-jetty-1.11.0-beta.jar google-oauth-client-servlet-1.11.0-beta.jar gson-2.1.jar gson-2.1.jar.properties guava-11.0.1.jar guava-11.0.1.jar.properties httpclient-4.0.3.jar httpcore-4.0.1.jar jackson-core-2.0.5.jar jackson-core-2.0.5.jar.properties jackson-core-asl-1.9.9.jar jackson-core-asl-1.9.9.jar.properties jdo2-api-2.3-eb.jar jetty-6.1.26.jar jetty-util-6.1.26.jar jsr305-1.3.9.jar transaction-api-1.1.jar xpp3-1.1.4c.jar 

I'm not sure what I am missing, but I need these libraries to continue the tutorial. If you need more information, I will be happy to provide it. I am new when it comes to the Google Calendar API. Any help is appreciated! Thanks!

+4
source share
1 answer

Unfortunately, Google has not updated the Java configuration source code at this time. You do not need these classes, and as others noted in their comments, they are deprecated.

Replace the import of "draft10" with:

 import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse; import com.google.api.services.calendar.CalendarScopes; 

Then replace the authorization code (from the comment "Step 1: Authorization β†’" and further):

 GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( httpTransport, jsonFactory, clientId, clientSecret, Arrays.asList(CalendarScopes.CALENDAR)).setAccessType("online") .setApprovalPrompt("auto").build(); String url = flow.newAuthorizationUrl().setRedirectUri(redirectUrl).build(); System.out.println("Please open the following URL in your browser then type the authorization code:"); System.out.println(" " + url); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String code = br.readLine(); GoogleTokenResponse response = flow.newTokenRequest(code) .setRedirectUri(redirectUrl).execute(); GoogleCredential credential = new GoogleCredential() .setFromTokenResponse(response); // Create a new authorized API client Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credential).build(); 

I had the same problem and I found the sample disk code for the update. I figured out my path and made it work. The "flow of authorization code" is described here .

+12
source

Source: https://habr.com/ru/post/1435790/


All Articles