开发者

Facebook realtime updates - doesn't get ping back

It took me some time, but I managed to get to the last point in real time updates, the challenge.

I know that when subscribing Facebook should ping my server, the problem is that it never happens, I always get the same response back:

{"error"开发者_如何学JAVA:{"type":"OAuthException","message":"(#2201) response does not match challenge, expected value = '1506372182', received=''"}}

It looks like it is able to connect to my server (every other callback url fails with address not available), however I don't see it calling me in the logs.

I'm using app engine:

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();

I'm handling both the user authentication and real time subscription in the same servlet.

When reading back the response I'm getting the above error and I don't see any call to my servlet (in the app engine logs). I'm sure I'm missing something.

Any help will be appreciated.


I'd ensure that Facebook can really hit your website. Once you get that part figured out, then you can use server logs to check for traffic and your error logs for anything programming related.


Ok, solved. The problem was with the permissions in web.xml, Facebook couldn't reach my page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜