1

我正在尝试在使用日历应用程序时了解 Google 服务和 OAuth 2.0。我遇到了这个问题,无法找到解决方案。请让我知道任何方式。calendar.builder在下面的代码中,我收到了已弃用的警告。另一种选择是什么?

public static Calendar build(GoogleCredential credentials) {
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JacksonFactory jsonFactory = new JacksonFactory();

com.google.api.services.calendar.Calendar service;

service = Calendar.builder(transport, jsonFactory)
 .setApplicationName("Meetrbus/1.0")
    .setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
      @Override
      public void initialize(JsonHttpRequest request) {
        CalendarRequest calendarRequest = (CalendarRequest) request;

        //TODO: Get an API key from Google's APIs Console:
       // https://code.google.com/apis/console.
        calendarRequest.setKey(<My Key>);
      }
    }).setHttpRequestInitializer(credentials).build();
4

1 回答 1

2

对于Calendar.Builder构造函数已经改变了一点:

public Calendar.Builder(HttpTransport transport,
                    JsonFactory jsonFactory,
                    HttpRequestInitializer httpRequestInitializer)

所以你的代码是:

service = new Calendar.Builder(transport, jsonFactory, credentials)
    .setApplicationName("Meetrbus/1.0")
    .setJsonHttpRequestInitializer(new JsonHttpRequestInitializer() {
        @Override
        public void initialize(JsonHttpRequest request) {
            CalendarRequest calendarRequest = (CalendarRequest) request;

            //TODO: Get an API key from Google's APIs Console:
            // https://code.google.com/apis/console.
            calendarRequest.setKey(<My Key>);
        }
    }).build();
于 2012-07-19T13:57:40.420 回答