由于错误而无法在Facebook上创建Webhook应用程序"无法验证提供的网址"
用于接收来自webhook的帖子调用的Servlet代码,如下所示
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("**************Entering Callback Servlet**************************");
Map<String, String[]> parametersMap = request.getParameterMap();
if (parametersMap.size() > 0) {
if (request.getParameter("hub.mode").equals("streamInit")) {
System.out.println("Verify Token: " + request.getParameter("hub.verify_token"));
System.out.println("Challenge number:" + request.getParameter("hub.challenge"));
String responseToClient = request.getParameter("hub.challenge");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(responseToClient);
response.getWriter().flush();
response.getWriter().close();
response.getWriter().append("Fetch-Mode").append(request.getParameter("hub.mode"));
response.getWriter().append("App Verify Token:").append(request.getParameter("hub.verify_token"));
response.getWriter().append("App Challenge No").append(request.getParameter("hub.challenge"));
System.out.println("**************Callback Successful**************************");
}
//response.getWriter().append("Served at: ").append(request.getContextPath());
}else{
System.out.println("**************Not an Facebook POST**************************");
}
System.out.println("**************Exiting Callback Servlet**************************");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
需要帮助我在这里失踪。
答案 0 :(得分:2)
Facebook希望指向确切的文件(例如:callback.php),你可以使用mod重写解决这个问题。只需提及它,https://证书必须有效并由公共机构签署(例如:comodo)。
答案 1 :(得分:1)
您可以使用https://ngrok.com/将https Webhooks发送到localhost dev服务器。
if (request.getParameter("hub.mode").equals("streamInit"))
到
if (request.getParameter("hub.mode").equals("subscribe"))
我不需要将它指向一个确切的文件。