Answer the question
In order to leave comments, you need to log in
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();
CalendarList feed = client.calendarList().list().setFields(CalendarInfo.FEED_FIELDS).execute();
model.reset(feed.getItems());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question