Advertisement
rdsedmundo

api Facebook

Mar 31st, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function (k) {
  2.     window.k = k;
  3.     k.___doc = k.document;
  4.     k.Exec = function () {
  5.         args = arguments;
  6.         var e = function () {}, t = function () {
  7.                 if (typeof args[0] === "function") {
  8.                     hasParameters = false;
  9.                     e = args[0];
  10.                 } else if (typeof args[1] === "function") {
  11.                     hasParameters = true;
  12.                     e = args[1]
  13.                 } else {
  14.                     e = undefined
  15.                 }
  16.             }();
  17.         if (e === undefined) return zkyFacebook.debug.log("Callback is undefined", 2);
  18.         if (hasParameters) e(args[0]);
  19.         else e();
  20.         zkyFacebook.debug.log("Callback called - at: " + Date.now(), 2)
  21.     };
  22.     k.zkyFacebook = function () {
  23.         return {
  24.             Init: function () {
  25.                 k.appId = arguments[0] || "0", k.cURL = arguments[1] || "cH.html", k.rstatus = arguments[2] || true, k.bCookie = arguments[3] || true, k.bxfbml = arguments[4] || true;
  26.                 d = ___doc.createElement("div");
  27.                 d.id = "fb-root";
  28.                 ___doc.body.appendChild(d);
  29.                 k.fbAsyncInit = function () {
  30.                     FB.init({
  31.                         appId: appId,
  32.                         channelUrl: cURL,
  33.                         status: rstatus,
  34.                         cookie: bCookie,
  35.                         xfbml: bxfbml
  36.                     });
  37.                     zkyFacebook.debug.log("Facebook auth loaded", 2);
  38.                     (k.zkyLoad)?zkyLoad():null;
  39.                 };
  40.                 this.LoadSDK()
  41.             },
  42.             LoadSDK: function () {
  43.                 var e, t = "facebook-jssdk",
  44.                     n = ___doc.getElementsByTagName("script")[0];
  45.                 if (___doc.getElementById(t)) return;
  46.                 e = ___doc.createElement("script");
  47.                 e.id = t;
  48.                 e.async = true;
  49.                 e.src = "//connect.facebook.net/en_US/all.js";
  50.                 n.parentNode.insertBefore(e, n);
  51.                 zkyFacebook.debug.log("SDK loaded", 1)
  52.             }
  53.         }
  54.     }();
  55.     k.zkyFacebook.utils = function () {
  56.         return {
  57.             printf: function (e) {
  58.                 len = e.match(/%/gi);
  59.                 for (i = 0; i <= len.length; i++) e = e.replace(/%/, arguments[i + 1]);
  60.                 return e
  61.             }
  62.         }
  63.     }();
  64.     k.zkyFacebook.debug = function __this() {
  65.         return {
  66.             log: function () {
  67.                 t = arguments[1] || 0;
  68.                 mth = ["log", "info", "warn", "error"][t] || "log";
  69.                 eval(zkyFacebook.utils.printf("console.%('%');", mth, (new Date).getHours() + ":" + (new Date).getMinutes() + ":" + (new Date).getSeconds() + " - " + arguments[0]))
  70.             }
  71.         }
  72.     }();
  73.     k.zkyFacebook.me = function () {
  74.         return {
  75.             getLoginStatus: function () {
  76.                 FB.getLoginStatus(function (e) {
  77.                     if (e.status === "connected") {
  78.                         return false
  79.                     } else if (e.status === "not_authorized") {
  80.                         return true
  81.                     } else {
  82.                         return true
  83.                     }
  84.                 });
  85.                 zkyFacebook.debug.log("Getting login status", 1)
  86.             },
  87.             login: function () {
  88.                 if (this.getLoginStatus()) {
  89.                     FB.login(function (e) {
  90.                         if (e.authResponse) {
  91.                             Exec(arguments[0]);
  92.                             zkyFacebook.debug.log("User is authed with FB", 1)
  93.                         } else {
  94.                             zkyFacebook.debug.log("User cancelled logging", 1)
  95.                         }
  96.                     })
  97.                 } else {
  98.                     Exec(arguments[0]);
  99.                     zkyFacebook.debug.log("User is already authed with FB", 1)
  100.                 }
  101.             }
  102.         }
  103.     }();
  104.     k.zkyFacebook.me.user = function () {
  105.         return {
  106.             name:(function () {
  107.                 FB.api("/me", function (e) {
  108.                     for (var t in e) alert(e[t] + " = " + t);
  109.                     window.fbUserName = e.name;
  110.                     return e.name
  111.                 })
  112.             })
  113.         }
  114.     }
  115. })(window);
  116. zkyFacebook.Init("164762683678240");
  117. k.zkyLoad = function (){
  118.      zkyFacebook.me.login(zkyFacebook.me.user.name);
  119.      alert("Loaded");
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement