需要帮助来实现Apify webhook。完成一项任务需要一些时间。我想添加一个Apify webhook,它将运行另一个任务,但不确定如何做到这一点。
$.ajax({
url : 'https://api.apify.com/v2/actor-tasks/XXXXXXX/runs?token=XXXXXXXX&waitForFinish=120',
method : 'POST',
contentType: 'application/json',
dataType: 'json',
data : JSON.stringify ({
"queries" : "Outreach link building"
}),
success:function(result) {
console.log(result);
}
});然后,webhook将调用以下任务:
$.ajax({
url : `https://api.apify.com/v2/datasets/${datasetId}/items?format=json`,
method : 'GET',
contentType: 'application/json; charset=utf-8',
success:function(response) {
console.log(response); // Items from dataset
}
});顺便说一句,如果我想实现我需要的方式是错误的,请让我知道你的建议。
发布于 2019-09-10 21:13:42
如果你根本不想在你的应用程序下面使用服务器,你想从客户端(前端)管理一切,并且同步运行的5分钟最大延迟对你来说太短了,你可以使用轮询。您只需调用run端点几次,直到它返回状态为succeeded。
但是,如果可以使用waitForFinish,只需执行此操作,然后发送第二个调用以获取
success:function(result) {
console.log(result);
// instead of this log, you need to put your second call here and use the `result.data.defaultDatasetId` as ID of the dataset
} 如果您必须等待超过300秒,则需要使用轮询。但我真的会避免这种情况,或者不使用带回调的ajax,而是使用更现代的fetch。
$.ajax({
url : 'https://api.apify.com/v2/actor-tasks/XXXXXXX/runs?token=XXXXXXXX&waitForFinish=120',
method : 'POST',
contentType: 'application/json',
dataType: 'json',
data : JSON.stringify ({
"queries" : "Outreach link building"
}),
success:function(result) {
console.log(result);
// Here instead of just logging, you get the run object back with its `status`. You also find an `id` there and you can periodically poll the run with this endpoint
https://apify.com/docs/api/v2#/reference/actors/run-object/get-run
} https://stackoverflow.com/questions/57871260
复制相似问题