Shubhashis
Shubhashis

Reputation: 10631

Android Studio with Google Calendar API V3

I wanted to try out google calendar API v3. I have Android Studio 1.0. I created a java endpoint module from Android Studio. I was following the official documentation here
If you follow the link I provided, you will see a line like this

Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
    .setApplicationName("applicationName").build();

Now what will be the httpTransport, jsonfactory and credentials here? Official documentation did not specify anything.

I also followed a sample in java from here.
This was done using Java Servlet and Eclipse. I am not familiar with that. It wont work on Android Studio.

Can anyone provide me a sample? or any direction to work with Calender API and Android Studio? Or what to do in the official sample mentioned above?

Upvotes: 1

Views: 1194

Answers (1)

tomrozb
tomrozb

Reputation: 26281

You should pass GoogleAccountCredential as the last argument

GoogleAccountCredential googleAccountCredential =
     GoogleAccountCredential.usingAudience(context, "server:client_id:" + WEB_CLIENT_ID);
     googleAccountCredential.setSelectedAccountName(userEmail);

What is WEB_CLIENT_ID you can find in many tutorials over the internet. It's basically ID which you can generate using Google Developers Console for given project.

Here's how to create Calendar instance with transport and JSON factory.

new Calendar.Builder(AndroidHttp.newCompatibleTransport(),
            AndroidJsonFactory.getDefaultInstance(), googleAccountCredential);

Upvotes: 1

Related Questions