Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Eclipse中使用Google日历API jar文件创建事件?_Java_Eclipse_Google Calendar Api - Fatal编程技术网

Java 如何在Eclipse中使用Google日历API jar文件创建事件?

Java 如何在Eclipse中使用Google日历API jar文件创建事件?,java,eclipse,google-calendar-api,Java,Eclipse,Google Calendar Api,我在后面遇到了困难。我正在EclipseIDE中编写一个简单的Java类,它能够在我的Google日历中插入一个新事件 我已经下载并将生成路径添加到我的项目中。此外,我还为谷歌日历API创建了凭据,并下载了client_secret.json文件 我正在使用: import com.google.api.client.util.DateTime; import com.google.api.services.calendar.model.Event; import com.google.api.

我在后面遇到了困难。我正在EclipseIDE中编写一个简单的Java类,它能够在我的Google日历中插入一个新事件

我已经下载并将生成路径添加到我的项目中。此外,我还为谷歌日历API创建了凭据,并下载了client_secret.json文件

我正在使用:

import com.google.api.client.util.DateTime;
import com.google.api.services.calendar.model.Event;
import com.google.api.services.calendar.model.EventAttendee;
import com.google.api.services.calendar.model.EventDateTime;
import com.google.api.services.calendar.model.EventReminder;

public class CreateEventCalendar {
    // Refer to the Java quickstart on how to setup the environment:
    // https://developers.google.com/google-apps/calendar/quickstart/java
    // Change the scope to CalendarScopes.CALENDAR and delete any stored
    // credentials.

    Event event = new Event().setSummary("Google I/O 2015").setLocation("800 Howard St., San Francisco, CA 94103")
            .setDescription("A chance to hear more about Google's developer products.");

    DateTime startDateTime = new DateTime("2015-05-28T09:00:00-07:00");
    EventDateTime start = new EventDateTime().setDateTime(startDateTime)
            .setTimeZone("America/Los_Angeles");event.setStart(start);

    DateTime endDateTime = new DateTime("2015-05-28T17:00:00-07:00");
    EventDateTime end = new EventDateTime().setDateTime(endDateTime)
            .setTimeZone("America/Los_Angeles");event.setEnd(end);

    String[] recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" };event.setRecurrence(Arrays.asList(recurrence));

    EventAttendee[] attendees = new EventAttendee[] { new EventAttendee().setEmail("lpage@example.com"),
            new EventAttendee().setEmail("sbrin@example.com"), };event.setAttendees(Arrays.asList(attendees));

    EventReminder[] reminderOverrides = new EventReminder[] {
            new EventReminder().setMethod("email").setMinutes(24 * 60),
            new EventReminder().setMethod("popup").setMinutes(10), };
    Event.Reminders reminders = new Event.Reminders().setUseDefault(false)
            .setOverrides(Arrays.asList(reminderOverrides));event.setReminders(reminders);

String calendarId = "primary";event=service.events().insert(calendarId,event).execute();System.out.printf("Event created: %s\n",event.getHtmlLink());
}}
如何在谷歌日历中插入新活动?我如何授权申请?如何使用创建的凭据

任何帮助都将不胜感激

更新:

Jan 04, 2017 2:04:54 AM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody: C:\Users\name\.credentials\calendar-java-quickstart
Jan 04, 2017 2:04:56 AM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner: C:\Users\name\.credentials\calendar-java-quickstart
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
    at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver.getRedirectUri(LocalServerReceiver.java:98)
    at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:76)
    at Quickstart.authorize(Quickstart.java:79)
    at Quickstart.getCalendarService(Quickstart.java:92)
    at Quickstart.main(Quickstart.java:104)
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more
我在其他网站上找到了可能的解决方案,但没有一个有效:

  • 在管理模式下运行eclipse
  • 在DriveQuickstart.class.getResourceAsStream(“/client\u secret.json”)中更改
    InputStream
    to
    InputStream in=newfileinputstream(“\\client\u secret.json”)

  • 当我启动Quickstart类时,会创建一个“StoredCredentials”文件

    你遇到了什么错误?请发帖。我刚刚更新了帖子,加入了我收到的错误信息。你遇到了什么错误?请发帖。我刚刚更新了帖子,加入了我收到的错误信息。