我已经写了一个小代码,我尝试在谷歌日历中添加一个带有appengine的事件,我试着理解这些,我的代码还没有工作,所以请求有人帮我提出一些想法吗?
我使用了来自Google的样本...所以如果授权我解决了这个问题,所以我尝试编写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);
}
}