SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Location
    Kolkata
    Posts
    0
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Facebook App using only Javascript SDK without any PHP

    Hi, I want to show a facebook login button on my blog using Facebook App.

    If the user is logged in facebook,
    His/Her photo will be shown on a <img id="FB_image" /> element
    and user can post message on facebook wall using a button with id="FB_post_msg"

    Else (i.e. if the user is not logged in)
    A login button will appear on my web.

    I have added my blog url in facebook app under Website with Facebook Login option as http://dibyendu-home.blogspot.com

    and also added the following code to my blog to authenticate the facebook app and just to check whether it is working or not...

    <div id='fb-root'/>
    <script>
    // Additional JS functions here
    window.fbAsyncInit = function() {
    FB.init({
    appId : '111111111111', // Original App ID is not given here
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml : true // parse XFBML
    });


    // Additional init code here
    FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
    alert('connected');
    } else if (response.status === 'not_authorized') {
    alert('not authorized');
    login();
    } else {
    alert('not logged in');
    login();
    }
    });
    };


    };

    // Load the SDK Asynchronously
    (function(d){
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = &quot;//connect.facebook.net/en_US/all.js&quot;;
    ref.parentNode.insertBefore(js, ref);
    }(document));
    </script>

    But the problem is that it is not showing anything...
    I don't know whether I am doing in the right way or not..
    Anyone pls help me out...
    If possible please provide instructions to do it...

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    _
    Last edited by AussieJohn; May 1, 2013 at 15:05. Reason: For some reason my post doubled up. Whoops.
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Hey Rani,

    There are 2 tiny errors in your code that are preventing it from running. The reason nothing happens is because these errors stop the JavaScript code from executing.

    You have an extra closing brace right before the comment "// Load the SDK Asynchronously" and inside that piece of code that loads the SDK, the url to the facebook All.js is surrounded by "&quot;" instead of actual quotes.

    I've highlighted the issues for you below:
    Code:
    // Additional JS functions here
    window.fbAsyncInit = function() {
        FB.init({
            appId : '111111111111', // Original App ID is not given here
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml : true // parse XFBML
        });
    
    
    
    
        // Additional init code here
        FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                alert('connected');
            } else if (response.status === 'not_authorized') {
                alert('not authorized');
                login();
            } else {
                alert('not logged in');
                login();
            }
        });
    };
    
    
    }; // << This is an extra brace
    
    
    // Load the SDK Asynchronously
    (function(d){
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = &quot;//connect.facebook.net/en_US/all.js&quot;; // << These &quot; should be "
        ref.parentNode.insertBefore(js, ref);
    }(document));
    </script>
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •