如何从 Box.com 中提取企业事件



这是我尝试使用 Box API 拉取企业事件的示例代码-

TimeZone tz = TimeZone.getTimeZone("UTC");
Calendar start = Calendar.getInstance(tz);
start.add(Calendar.MONTH, -1); // retrieve events for last one month
Calendar end = Calendar.getInstance(tz);
try {
    EventLog el = EventLog.getEnterpriseEvents(api, start.getTime(), end.getTime(), BoxEvent.Type.values());
    System.out.println("Total- " + el.getSize());
    for (Iterator<BoxEvent> iterator = el.iterator(); iterator.hasNext();) {
        System.out.println(iterator.next().toString());
    }
} catch (BoxAPIException ex) {
    ex.printStackTrace();
    System.out.println(ex.getResponse());
}

而我得到的实际错误——

{"type":"error","status":400,"code":"bad_request","help_url":"http://developers.box.com/docs/#errors","message":"created_after 已超过过去一年,API 仅支持从现在开始的过去一年开始的时间范围","request_id":"310879445579d0cc0fd33"}

错误是"start"似乎太旧(至少 1 年),并导致 400 错误,因为 API 不支持它。

问题似乎出在新的Box Java SDK 1.0.0中 — 必须更新com.box.sdk.EventLog:

    String afterString = BoxDateFormat.format(after);
    String beforeString = BoxDateFormat.format(before);
    // this one added by me to encode dates
        try {
            afterString = URLEncoder.encode(afterString, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            // what do we do here?
        }
        try {
            beforeString = URLEncoder.encode(beforeString, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            // what do we do here?
        }
        URL url = ENTERPRISE_EVENT_URL_TEMPLATE.build(api.getBaseURL(), afterString, beforeString);

最新更新