Monday, October 31, 2011

How to compare the two dates in PHP

function compare_date ($date_one,$date_two){


//your input should be dd/mm/yy
$arr_date_one= explode ("/", $date_one);
$arr_date_two= explode ("/", $date_two);
//remove the '/'


$days_one = $arr_date_one[0];
$months_one = $arr_date_one[1];
$year_one = $arr_date_one[2];

$days_two = $arr_date_two[0];
$months_two = $arr_date_two[1];
$year_two = $arr_date_two[2];

$date_one_jul = gregoriantojd($days_one , $months_one , $year_one );
$date_two_jul = gregoriantojd($days_two , $months_two , $year_two );

return $date_one_jul - $date_two_jul ;
}




//out put will be  +/- value depend on your parameters

Saturday, July 30, 2011

How to get news feed using facebook API

$app_id = 'APP_ID';
    $app_secret = "APP_SECRET";
    $my_url = "http://YOURDOMAIN/";
  
    $code = $_REQUEST["code"];

    if(empty($code)) {
        $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
            . $app_id . "&redirect_uri=" . urlencode($my_url)."&scope=email,read_stream,publish_stream";

        echo("<script> top.location.href='" . $dialog_url . "'</script>");
    }

    $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
        . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
        . $app_secret . "&code=" . $code;

    $access_token = file_get_contents($token_url);
    $graph_url = "https://graph.facebook.com/me?" . $access_token;
    $user = json_decode(file_get_contents($graph_url));
  
  
   //print the current user details
    print_r($user);
   
 
    $query = "https://api.facebook.com/method/fql.query?query=";
    $query .= urlencode("SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0");

    //$query .= "&access_token=".$access_token."&format=json";
    $out = file_get_contents($query);
    $response = json_decode($out);
    
    //print the current users news feeed
    print_r($response);