Calendar API and OAuth

2019-09-09 02:39发布

问题:

From a lot of examples on the web, i am trying out a calendar application on my own. These examples used GoogleAccessProtectedResource during the calendar build. But when I tried it it says its been deprecated. Can someone please tell me what is the correct way to implement this?

public static Calendar build(String accessToken) {
  HttpTransport transport = AndroidHttp.newCompatibleTransport();
  JacksonFactory jsonFactory = new JacksonFactory();
  GoogleAccessProtectedResource accessProtectedResource =
      new GoogleAccessProtectedResource(accessToken);
  ...
}

回答1:

The Javadocs for the current version of the Google API JAVA Client library say this:

Deprecated. (scheduled to be removed in 1.11) Use GoogleCredential

See the Google OAuth wiki pages for an example on how to use it:

GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
Plus plus = Plus.builder(new NetHttpTransport(), new JacksonFactory())
    .setApplicationName("Google-PlusSample/1.0")
    .setHttpRequestInitializer(credential)
    .build();