Sunday, May 15, 2011

file_get_contents php method call to facebook loading very slow

when try to get content from an URL, php provide a method "file_get_contents", sometime when you use this method it might takes too long to load.

the following code is used to get the user basic profile from facebook,

$graph_url = "https://graph.facebook.com/me?" . $access_token;
$fbdetail = file_get_contents($graph_url);
$user = json_decode($fbdetail);

for me, file_get_contents takes 5-10 second to load the above code, some say its an DNS issues, below is another function to replace file_get_contenst, it takes less than 3 second for me to load.

just include the below code and replace "file_get_contents" with "get_url"

function get_url($url)
 {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  $tmp = curl_exec($ch);
  curl_close($ch);
  return $tmp;
 }

Tuesday, May 3, 2011

Login with Facebook Button using Javascript

The following shows how to put a "login with facebook" button on your website, visitor can skip the register process and you can request a access token with this script and save it in a cookie or session, also you can access the visitor facebook basic information.

First, assume that your page is http://www.mylovelystory.com/index.html
Then, put this script inside your head tag

//Replace YOUR_APP_ID to you facebook application ID <script src="http://connect.facebook.net/en_US/all.js#appId=YOUR_APP_ID&xfbml=1"></script> //Replace YOUR_APP_ID to you facebook application ID

And inside you HTML tag, DivLogin consist the login button, DivLogged consist the profile picture of the logged facebook users

Login with Facebook

hope this acticle helps, drop a comment and leave your email if you need my help.

Wednesday, April 27, 2011

Multi Friend Selector Popup using FB.UI for Facebook Tab and App

Facebook tab only takes 520px, or if you develop facebook apps with width less than 580, you will get the invitation preview dialog cuts off when you are using the multi friend selector.

I can't find any way to resize the invitation preview dialog, so i made a popup multi friend selector.

First of all, remember to do FB.init, get the code here, I'm using the "Asynchronous Loading"

In invite.php(or where you want to put the MFS in), put the below code




Now the button to call up the multi friend selector:

    



Here's some important notes:
1) display: 'popup' - without this, the FB.UI won't works in facebook tab
2) display: 'dialog' - does not works in facebook tab, use this in facebook app, it looks better
3) Once invitation is send, it will goes to share.php, share.php will be the page you get IDS from your mfs, you can echo a javascript windows close at share.php at the end of your code
4) back to invite.php, you'll see i put both self.location.href = 'thank.php'; in the response statement, whether there is a response or not, i direct the facebook tab to thank.php

Hope this help.