Sunday, January 23, 2011

Facebook API calls with Javascript

The social networking app I'm writing with my would be mentor requires integration with facebook.  Given the ubiquity of javascript, I decided, what better way to integrate with facebook than through their Javascript SDK?


While testing a simple case I encountered a frustrating error where facebook api calls seemed to simply stop functioning -- no init's, login information, graph api calls, no nothing.  There wasn't even an unsuccessful login session object returned.  And it seemed as though nothing had changed.  I was ready to blame facebook, but after a little bit more debugging I discovered the cause:

<pic to come>

All facebook javascript sdk calls with a specific app ID must be made from the same domain as the canvas url.  This is very possibly a manifestation of the same origin policy, a rather stringent security necessity for Javascript.  In any event, with that discovery, I was able to continue testing.  However finding the cause of the bug was quite difficult, since facebook's own error response for the issue was virtually nonexistent, and many forums confused the cause of the lack of function with erratic facebook code state.  Ultimately nothing beats personal debugging

No comments:

Post a Comment