A
A
Alviere2014-06-20 23:49:24
Google
Alviere, 2014-06-20 23:49:24

Is there a way to use the Google Calendar API in an Android app?

Hello!
Faced such a problem: I need to interact with Google Calendar from the Android application (namely, the web version). Since it is necessary to use the web version, the use of Content Providers and Intents for the Calendar application is eliminated.
I tried to use google-api-client-library, but unfortunately, neither the example provided in the documentation, nor all my attempts could make this animal work. Below is the authorization code and attempts to obtain data:

// Объявляем объекты для взаимодействия с Google Calendar
    final HttpTransport transport = AndroidHttp.newCompatibleTransport();
    final JsonFactory jsonFactory = GsonFactory.getDefaultInstance();

    // Объявляем объект для хранения учетной записи пользователя (oAuth 2.0)
    GoogleAccountCredential credential;

    // Объявляем объект клиентской библиотеки для взаимодействия с Google Calendar
    com.google.api.services.calendar.Calendar client;

    // Подключаем аккаунт Google
    credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(CalendarScopes.CALENDAR));
    // Получаем настройки, вдруг в приложение заходят не в первый раз
    SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
    credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));

    // Подключаем клиент библиотеки
    client = new com.google.api.services.calendar.Calendar.Builder(
            transport, jsonFactory, credential).setApplicationName("IlyaLim-TestApp/1.0")
            .build();

Getting a list of calendars (in AsyncTask):
CalendarList feed = client.calendarList().list().setFields(CalendarInfo.FEED_FIELDS).execute();
        model.reset(feed.getItems());

When executing this piece in AsyncTask, it constantly throws an IOException without an error description.
I have already tried everything I know and can and found on the Internet. Hence the actual question:
Does anyone have information or a link to a complete, detailed and (!) Working example / tutorial for using google-api-client-android or an example of working with the Google API directly (REST) ​​in Java?
Many thanks in advance to everyone!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question