现在我正在尝试在 Asana 中设置一个 webhook,以向我发送有关我的 Asana 项目中特定任务的事件更新。我是新手,所以在阅读和回答时请记住这一点,谢谢。这也是我在这里的第一篇文章,所以请放轻松。这是我正在运行的代码。
收到通知的 WCF:
public string ReceiveHooks(Stream JSONdataStream)
{
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
if (headers.AllKeys.Contains("X-Hook-Secret"))
{
var key = headers["X-Hook-Secret"];
WebOperationContext.Current.OutgoingResponse.Headers.Add("X-Hook-Secret", key);
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
}
//Handle Json body
using (var reader = new StreamReader(JSONdataStream))
{
List<AsanaEvent> listEvent = null;
string values = reader.ReadToEnd();
logger.Info("Asana receive hook successful: " + values);
return "true";
}
return "False";
}
我创建 Webhook 的请求:
var client = new RestClient("https://app.asana.com/api/1.0/webhooks");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("authorization", "Bearer 0/<key>");
request.AddParameter("application/x-www-form-urlencoded", "resource=234806314393357&target=https%3A%2F%2Fmywebservice.com%2FWCFService.svc%2FReceiveHooks", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
我可以收到 HookId:
{
"data": {
"id": 235053304,
"target": "https://myservice.com/WCFService.svc/ReceiveHooks",
"active": true,
"created_at": "2016-12-22T16:02:29.899Z",
"last_failure_at": null,
"last_failure_content": "",
"last_success_at": null,
"resource": {
"id": 2349951,
"name": "My Task Name"
}
}
}
但是当我尝试通过 Id 获取 webhook 时,我收到了错误消息:
"message": "webhook: Unknown object: 235053304"
有人对此错误消息有任何线索吗?我假设进行握手和处理接收到的钩子的代码在同一个地方。?
非常感谢