0

我写了一个小代码,我尝试用 appengine 在谷歌日历中添加一个事件,我试图理解 baiscs,我的代码还没有工作,所以有人可以帮我一些想法吗?

我使用了来自谷歌的示例......所以如果授权它已经解决了问题,所以我尝试编写 api 调用,但它似乎不适用于我

  public class CalendarSampleServlet
    extends AbstractAppEngineAuthorizationCodeServlet {

  /**
   * Be sure to specify the name of your application. If the application name is {@code null} or
   * blank, the application will log a warning. Suggested format is "MyCompany-ProductName/1.0".
   */
  private static final String APPLICATION_NAME = "m3atest";

  private static final long serialVersionUID = 1L;

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {
    // Get the stored credentials using the Authorization Flow
    AuthorizationCodeFlow authFlow = initializeFlow();
    Credential credential = authFlow.loadCredential(getUserId(req));
    // Build the Calendar object using the credentials
    @SuppressWarnings("unused")
    Calendar calendar = new Calendar.Builder(
        Utils.HTTP_TRANSPORT, Utils.JSON_FACTORY, credential)
        .setApplicationName(APPLICATION_NAME)
        .build();

    // Add the code to make an API call here.

    Calendar userCal=Utils.loadCalendarClient();
    Event event =new Event();
   Date date=new Date();
   DateTime time=new DateTime(date,TimeZone.getDefault());
   event.setStart(new EventDateTime().setDateTime(time));
   event.setEnd(new EventDateTime().setDateTime(time) );
   event.setDescription("test_event");
   userCal.events().insert("test@test.com", event);




    // Send the results as the response
    resp.setStatus(200);
    resp.setContentType("text/html");
    PrintWriter writer = resp.getWriter();
    writer.println("done");

  }
  @Override
  protected AuthorizationCodeFlow initializeFlow() throws ServletException, IOException {
    return Utils.initializeFlow();
  }

  @Override
  protected String getRedirectUri(HttpServletRequest req) throws ServletException, IOException {
    return Utils.getRedirectUri(req);
  }

}

4

0 回答 0