I use the Google Calendar api to get events from the shared calendar. In the Google developer console, I created a service account key (json), which I use to configure GoogleCredential in Android code as follows:
AssetManager am = getAssets(); InputStream inputStream = am.open("key-file-name.json"); GoogleCredential credential = GoogleCredential.fromStream(inputStream); credential =credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/calendar.readonly"));
Then I use this GoogleCredential to get the calendar object
Calendar client = new Calendar.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), credential).setApplicationName("someAppName").build();
Then I get the following 5 events from this calendar
com.google.api.services.calendar.model.Events nextEvent = client.events().list(" public-calendar-id@group.calendar.google.com ") .setTimeMin(new DateTime(new java.util.Date(), java.util.TimeZone.getDefault())) .setMaxResults(5) .setOrderBy("startTime") .setSingleEvents(true) .setShowDeleted(false) .execute();
Although this code works fine when debugging when working in android studio, when I create for release (a sign with a keystore file), it does not work. It simply returns the following exception:
com.google.aacbc: 404 Not found 3097-3187 / com.news.apoelnews W / System.err: Not found 3097-3187 / com.news.apoelnews W / System.err:
at com.google.aacdacb (Unknown source)
Please, help!
UPDATE I added the use of the Android API to the code as follows:
com.google.api.services.calendar.model.Events nextEvent = client.events().list(" public-calendar-id@group.calendar.google.com ") .setTimeMin(new DateTime(new java.util.Date(), java.util.TimeZone.getDefault())) .setMaxResults(5) .setOrderBy("startTime") .setSingleEvents(true) .setShowDeleted(false) .setKey("api-key-string_from_developer_console")) .execute();
This throws the following exception:
W. / System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden W / System.err: "code": 403, W / System.err: "errors": [{W / System. err: "domain": "usageLimits", W / System.err:
"message": "There is a limit for each IP address or each referrer to your API key, and the request does not meet these restrictions.
Note that API keys are created using debugging and SHA-1 release.