谷歌凭证+日历范围问题

时间:2014-02-03 13:21:52

标签: google-calendar-api credentials

我正试图通过谷歌凭证访问我的谷歌日历。

 GoogleCredential credentials = new GoogleCredential.Builder().setTransport(httpTransport)
                .setJsonFactory(jsonFactory)
                .setServiceAccountId("xxx@developer.gserviceaccount.com")
                .setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/calendar"))
                .setServiceAccountPrivateKeyFromP12File(new File("Disk:\\xxx-privatekey.p12"))
                .setServiceAccountUser("xxx@gmail.com").build();

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

但是当我想用

这样的日历做smth时
com.google.api.services.calendar.model.Calendar calendar = service.calendars().get("primary").execute();

        System.out.println(calendar.getSummary());

我收到错误

com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
  "error" : "access_denied",
  "error_description" : "Requested scopes not allowed: https://www.googleapis.com/auth/calendar"
}

0 个答案:

没有答案