3

I am developing an applicaiton using Google Calendar API v3 and Service account mode to have access. My application seems able to create new calendar without problem, but when I am going to check the result using Google Calendar standard web app I can't see nothing. This is strange because fetching CalendarList return the proper calendar list. Someone know why this happens? There is some limitation with calendar created with Service Account?

Thank you for your help. Alberto

UPDATE 1 :

Here a snippet of my code

HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
            .setServiceAccountScopes(Collections.singleton(CalendarScopes.CALENDAR))
            .setServiceAccountPrivateKeyFromP12File(new File(KEY_P12))
            // .setServiceAccountUser("user@example.com")
            .build();

         Calendar service = new com.google.api.services.calendar.Calendar.Builder(httpTransport, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME).build();

        com.google.api.services.calendar.model.Calendar content = new com.google.api.services.calendar.model.Calendar();
        content.setSummary("A calendar");
        service.calendars().insert(content).execute();

UPDATE 2 :

Someone suggest to me to add to credentials the service account user (then de-comment .setServiceAccountUser("user@example.com") the code above, but it doesn't work. In this case I can't create neither a calendar and I receive when I call service.calendars().insert(content).execute(); and I receive

400 Bad Request
{
  "error" : "access_denied"
}
Alberto R.
  • 161
  • 2
  • 10
  • you're right, sorry :) – Alberto R. Sep 14 '13 at 17:37
  • Have you any idea? :( – Alberto R. Sep 15 '13 at 21:59
  • I have the same problem. Have you been able to resolve this? – Drux Jan 08 '14 at 10:04
  • possible duplicate of [How to correctly obtain user's Calendar events using service account?](http://stackoverflow.com/questions/17210821/how-to-correctly-obtain-users-calendar-events-using-service-account) – Drux Jan 08 '14 at 10:20
  • I think you're missing Acl entry for the calendar created. See this http://stackoverflow.com/questions/21094240/who-owns-calendars-created-by-service-account-via-google-calendar-api-and-how-ca – eeee Dec 18 '15 at 17:59

2 Answers2

0

Use the CalendarList.get() function to confirm the Calendar is not hidden=true in the user's calendar list.

Jay Lee
  • 13,415
  • 3
  • 28
  • 59
  • Hi Jay, I tried your suggestion and printed the result service().calendarList().get(calendarId).execute().toPrettyString(); { "accessRole" : "owner", "backgroundColor" : "#fa573c", "colorId" : "4", "etag" : "\"HvdNzJLFsPN6WzLOxlO1URKnJIE/ji0r5Uh3FsdbdNcKGxyRG7OA8n8\"", "foregroundColor" : "#000000", "id" : "mo012ecmkf3mrqmp5hjctj630s@group.calendar.google.com", "kind" : "calendar#calendarListEntry", "selected" : true, "summary" : "deviceId", "timeZone" : "UTC" } Maybe because I newb with G API but I can't retrieve 'hidden' value – Alberto R. Sep 16 '13 at 15:01
  • I delve into the api, the hidden value is null then CalendarListEntry#isHidden method return false :-\ – Alberto R. Sep 16 '13 at 16:34
0

I think that you have an incomplete GoogleCredential. Try with ClientSecrets and refresh token.

    List<String> scopes = new ArrayList<String>();
    scopes.add("https://www.google.com/m8/feeds/");
    GoogleCredential credential = new  GoogleCredential.Builder()
    .setTransport(new NetHttpTransport())
    .setJsonFactory( new JacksonFactory())
    .setServiceAccountId("id@developer.gserviceaccount.com")
    .setServiceAccountPrivateKeyFromP12File(new File("privatekey.p12"))
    .setClientSecrets("clientID", "clientSecret")
    .setServiceAccountScopes(scopes)
    .build();
    credential.refreshToken();

Regards

Oscar López
  • 381
  • 2
  • 8
  • 1
    Where do you get those values: `clientID`, `clientSecret`? Besides, the Java client seems to have all the credentials it needs to create calendars, so how could it be that its credentials are incomplete? – Drux Jan 08 '14 at 10:05