用java处理box api中的事件

用java处理box api中的事件,java,box-api,Java,Box Api,我是box api的新手,对使用新版本的box java sdk处理事件很感兴趣。我已经阅读了有关事件的文档,只找到了以下代码 如果有人能在代码方面帮助我,例如,处理文件上传事件,我将不胜感激 BoxAPIConnection api = new BoxAPIConnection("YOUR-DEVELOPER-TOKEN"); EventStream stream = new EventStream(api); stream.addListener(new EventL

我是box api的新手,对使用新版本的box java sdk处理事件很感兴趣。我已经阅读了有关事件的文档,只找到了以下代码

如果有人能在代码方面帮助我,例如,处理文件上传事件,我将不胜感激

    BoxAPIConnection api = new BoxAPIConnection("YOUR-DEVELOPER-TOKEN");
    EventStream stream = new EventStream(api);
    stream.addListener(new EventListener() {
        public void onEvent(BoxEvent event) {
            // Handle the event.
            ???? Need help here ????
        }
    });
    stream.start();

这里有事件列表:

那么你在哪里???在代码中尝试

if(event == ITEM_UPLOAD) 
{
 //your action
}


or 

if(event == "ITEM_UPLOAD") 
{
{
 //your action
}
}
或者这可能是正确的:

if(event.type == "ITEM_UPLOAD") 
    {
     //your action
    }
要查看您得到的事件,请在OneEvent()中写入以下内容:


您使用
EventListener
的方法是正确的。在您的
onEvent(BoxEvent)
方法中,您首先需要使用以下内容筛选您感兴趣的事件类型:

if (event.getType() == BoxEvent.Type.ITEM_UPLOAD) {
    // Do something
}
您还可以找到支持的事件类型的完整列表

一旦知道事件类型,就可以将事件源强制转换为适当的类型。例如,如果我们正在处理一个
BoxEvent.Type.ITEM\u UPLOAD
事件,那么事件源将是一个
BoxItem

if (event.getType() == BoxEvent.Type.ITEM_UPLOAD) {
    BoxItem uploadedItem = (BoxItem) event.getSource();

    // Do something with the uploaded item. For this example, we'll just print
    // out its name.
    BoxItem.Info itemInfo = uploadedItem.getInfo();
    System.out.format("A file named '%s' was uploaded.\n", itemInfo.getName());
}

很抱歉,您的示例不起作用,解决方案是event.getType()。我想使用event.getSorce()和event.parseJsonMember(成员)处理事件响应,但我不知道如何做。
if (event.getType() == BoxEvent.Type.ITEM_UPLOAD) {
    BoxItem uploadedItem = (BoxItem) event.getSource();

    // Do something with the uploaded item. For this example, we'll just print
    // out its name.
    BoxItem.Info itemInfo = uploadedItem.getInfo();
    System.out.format("A file named '%s' was uploaded.\n", itemInfo.getName());
}