Facebook JavaScript SDK with Graph API and Prototype JS

I was thinking to post from long time. I could not had time as I am busy these days because of school and work. I was reading new Facebook Graph API to solve one bug at my workplace. I could not find any straight forward example for that. So, I thought that I should post something so, it could be helpful for rookies and new bees…!!!

You can check out here. Example Page

8 thoughts on “Facebook JavaScript SDK with Graph API and Prototype JS

  1. Like tag seems to be wrong in that code… should be like on working example page

  2. Well, I have !!! But, I have added OpenGraph Tags in my page meta!!!

  3. I’m new to web related stuff, so please spare if my question is trivial. What is the role the web server plays over here ? I tried to run your html file from the local file system, but that doesn’t work. Error console shows an error “FB not found”. I’m trying to understand if the FB javascript sdk has to be used in conjunction with a web server, or if it can be used stand alone in local static html files. What is expected of the web server?

  4. Also, can you please share your application settings ?

  5. Hello Kumar, I guess new Facebook JavaScript SDK is more clean but not like previous REST API. It is more specific in terms of usability.

    When you get FB not found or undefined that means that object is not initiated properly. Here, FB [Object object] is undefined.

    Now, about using webpage on localhost. My Facebook App has Callback URL, pointing to my hosted domain. If you want to use my example on the localhost then you need to register a Facebook App at http://www.facebook.com/developers/ and set up Callback URL.

    If you have some questions then feel free to ask.

  6. I’m not sure if I was able to communicate my question well. If I have a HTML file in my local directory, and load into the browser as say file:///home/user/fb.html, is it possible that I’ll be able to authenticate and make use of FB API ?

    Basically I tried the javascript sdk (http://github.com/facebook/connect-js) example file jquery/login.html, and I tried running it from the local disk. It logged me in, but wasn’t able to make API calls (didn’t get a session. response.session was NULL).

    Is what I’m trying to do possible?

  7. Check OnLoad() function in the code.

    window.fbAsyncInit = function() {
    FB.init({appId: ‘210189452626’, cookie: true, logging: true, status: true, xfbml: true});
    };
    (function() {
    var e = document.createElement(‘script’);
    e.async = true;
    e.src = document.location.protocol + ‘//connect.facebook.net/en_US/all.js’;
    document.getElementById(‘fb-root’).appendChild(e);
    }());

    You need to register your Facebook App and replace your appId with my appId, which is “210189452626”. Here is link to screenshot of my setting page. http://gaurangjadia.com/blog/2010/06/07/facebook-javascript-sdk-with-graph-api-and-prototype-js/facebookappsetting/

  8. I tried changing the application setting’s URL to localhost, as in the screen shot you shared with me, and checked again (just to be clear, I’m loading file:///tmp/Facebook_JS_SDK.html in my browser).

    Upon a little debugging, figured out that the document.location.protocol is ‘file:’, and the page was trying to load the facebook js from local file. I corrected that, but it still doesn’t take me very far. I do get a popup login window, and I’m logged in successfully, but after that it does nothing. (I do get actually logged into facebook, but the console log in your html indicates a failed login).

    Would it be possible for you to try this and let me know how it goes?

    Thanks a lot for your help.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.