Facebook实时更新 - 没有ping回来

时间:2011-06-08 19:29:43

标签: facebook google-app-engine

我花了一些时间,但我设法在实时更新的最后一点,即挑战。

我知道订阅Facebook时应该ping我的服务器,问题是它永远不会发生,我总是得到相同的回复:

{“error”:{“type”:“OAuthException”,“message”:“(#2201)回复与挑战不匹配,预期值='1506372182',已收到=''”}}

看起来它能够连接到我的服务器(每个其他回调网址都失败,地址不可用),但我没有看到它在日志中呼叫我。

我正在使用应用引擎:

public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
...

else if (parameters.containsKey("hub.mode")) {
            log.info("doing hub.mode");
            // Check that challenge is valid.
            if (parameters.get("hub_verify_token").equals(Constants.FACEBOOK_VERIFY_TOKEN)) {
                log.info("hub.mode test is valid");
                resp.setContentType("text/plain");
                resp.getWriter().print(req.getParameter("hub.challenge"));
            }

        }
...


// I want real time information on a specific user, on its feeds.
        String data = URLEncoder.encode("object", "UTF-8") + "="
                + URLEncoder.encode("user", "UTF-8");
        data += "&" + URLEncoder.encode("fields", "UTF-8") + "="
                + URLEncoder.encode("feed", "UTF-8");
        // Send real time updates to this URL.
        data += "&" + URLEncoder.encode("callback_url", "UTF-8") + "="
                + URLEncoder.encode(reconstructedURL.toString(), "UTF-8");
        // A token used to verify that it is actually me who is running the verification process.
        data += "&" + URLEncoder.encode("verify_token", "UTF-8") + "="
                + URLEncoder.encode(Constants.FACEBOOK_VERIFY_TOKEN, "UTF-8");
        data += "&"
                + URLEncoder.encode("access_token", "UTF-8")
                + "="
                +Constants.FACEBOOK_APP_CODE + "|"
                        + Constants.FACEBOOK_APP_SECRET;
        // Subscribe by doing a post.
        URL url = new URL(String.format(
                "https://graph.facebook.com/%s/subscriptions?access_token=%s",
                Constants.FACEBOOK_APP_CODE, accessToken));
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        log.info(String.format("Sent the following data '%s'", data));
        wr.write(data);
        wr.flush();

我在同一个servlet中处理用户身份验证和实时订阅。

当回读响应时,我收到上述错误,我没有看到任何对我的servlet的调用(在app引擎日志中)。 我确定我错过了什么。

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

我确保Facebook可以真正打到你的网站。一旦你弄清楚了那部分,你就可以使用服务器日志来检查流量和你的错误日志,以了解与编程相关的任何内容。

答案 1 :(得分:1)

好的,解决了。问题在于web.xml中的权限,Facebook无法访问我的页面。

相关问题