check if the user log-in to facebook

Discussion in 'Facebook API' started by subhinajjar, Jul 10, 2012.

  1. #1
    I have app on facebook and i write all the code that make me post to the wall of user who read the article on my site just like the yahoo criteria . but now i want to know who is logged in to facebook and if he doesn't logged in to facebook he will not able to read the article on my site and i must enforce him to logged in by display login window.
    can any body help me on this.
    and this is my code:

     <html><head>
            <meta property="fb:app_id" content="#######" />
    		<meta property="og:title" content="3eesho reading club" />
    		<meta property="og:type" content="website" />
    		<meta property="og:url" content="http://3eesho.com/fb/subhitest/test_PAGE" />
    		<meta property="og:site_name" content="3eesho.com" />
    		<meta property="og:image"       content="http://ogp.me/logo.png" /> 
    </head>
    		<body>
    <script type="text/javascript">
    function getCookie(c_name)
    {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
      {
      x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
      y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
      x=x.replace(/^\s+|\s+$/g,"");
      if (x==c_name)
        {
        return unescape(y);
        }
      }
    }
    function setCookie(c_name,value,exdays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
    }
    function checkCookie()
    {
    var a=document.location.href;
    var b=a.split("/");
    var username=getCookie("username");
    if (username==null || username=="")
      {
      alert("thank you for visit this Id:"+b[4]);
    	username=b[4];
    	myFunction();
        setCookie("username",username,365);
      }
    else 
      {
      alert("this Id visited:"+b[4]);
      if(username!=b[4])
      {
      myFunction();
      setCookie("username",b[4],365);
      }   
      }
    }
    function myFunction()
    {
    var x;
    var r=confirm("did you want to publish this article to your wall on facebook");
    if (r==true)
      {
      x=alert("the article published!");
      graphStreamPublish();
      }
    else
      {
      x=alert("the article doesn't publish!");
      }
    }
    </script>
    <script>
                    (function(d, s, id) {
                                                    var js, fjs = d.getElementsByTagName(s)[0];
                                                    if (d.getElementById(id)) return;
                                                    js = d.createElement(s); js.id = id;
                                                    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=452488354765730";
                                                    fjs.parentNode.insertBefore(js, fjs);
                                                    }(document, 'script', 'facebook-jssdk'));
    //FB App Script
                    var button;
                    var userInfo;
                    window.fbAsyncInit = function() {
                                    FB.init({ appId: '#######',
                                    status: true,
                                    cookie: true,
                                    xfbml: true,
                                    oauth: true});
                                    showLoader(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);
                    }());
                    //stream publish method
                    function graphStreamPublish(){
    								alert("graphStreamPublish");
    					            showLoader(true);
                                    FB.api('/me/feed', 'post',
                                    {
    								 message : "\u0642\u0631\u0627 \u0647\u0630\u0627 \u0627\u0644\u0645\u0642\u0627\u0644 \u0639\u0644\u0649 \u0639\u064A\u0634\u0648.\u0643\u0648\u0645",   
    												link    : document.location.href+'?utm_campaign=spring&utm_medium=referral&utm_source=exampleblog'+target="_blank",
    												},
                                    function(response) {
                                                    showLoader(false);
                                                    if (!response || response.error) {
                                                    //alert('Error occured');
                                                    } 
    												else
            {
    			
                alert("Posted as "+response.id);
            }
                                    });
                    }
                    function showLoader(status){
                                    if (status)
                                                    document.getElementById('loader').style.display = 'block';
                                    else
                                                    document.getElementById('loader').style.display = 'none';
                    }
    </script>
    <a href="#" onclick="checkCookie()">Testing</a>
    <div class="fb-login-button" data-show-faces="true" data-width="180" data-max-rows="1" scope="publish_actions"></div>
    		<div id="loader" style="display:none"></div>
    		</body>
    </html>
    Code (markup):
     
    subhinajjar, Jul 10, 2012 IP
  2. walime

    walime Greenhorn

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    what is facebook API ?
     
    walime, Jul 10, 2012 IP
  3. subhinajjar

    subhinajjar Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i don't understand you????
     
    subhinajjar, Jul 11, 2012 IP