Skip to content
February 4, 2011 / ranacse05

Show Facebook Group Wall on web site

I was working last night and my task was to show the facebook groups wall on a normal website . It can be done easily using facebook graph api after working an hour it was done. So lets discuses the steps here.

And the output will be something like this

Facebook Group wall

First get the group name,description and photo.

$group_id = '2204685680';
$url1 = 'https://graph.facebook.com/'.$group_id;
$des = json_decode(file_get_contents($url1));

This will return all the basic info and those will be in Json format, after decoding that we'll get some data

stdClass Object

(
    [id] => 2204685680
    [version] => 0
    [owner] => stdClass Object
        (
            [name] => Fatih Beyaz
            [id] => 709103042
        )

    [name] => PHP
    [description] => PHP: Hypertext Preprocessor

For anyone who uses PHP.
    [privacy] => OPEN
    [icon] => http://b.static.ak.fbcdn.net/rsrc.php/y_/r/CbwcMZjMUbR.png
    [updated_time] => 2006-07-09T11:39:30+0000
)

Now we have to pull the posts. For this we need to add feed at the end of the previous url , and the code will be like 

$url2 = "https://graph.facebook.com/{$group_id}/feed";
$data = json_decode(file_get_contents($url2));

This will return last 25 wall post , we can get more if we want by using &limit=NUMBER .

For the design lets write some css .

<style type="text/css">
 .wrapper {
 width:300px;
 border:1px solid #ccc;
 font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
 float:left;
 }

 .top {
 margin:5px;
 border-bottom:2px solid #e1e1e1;
 float: left;
 width:290px;
 }

 .single {
 margin:5px;
 border-bottom:1px dashed #e1e1e1;
 float:left;
 }

 .img {
 float:left;
 width:60px;
 text-align:center;
 margin:5px 5px 5px 0px;
 border-right:1px dashed #e1e1e1;
 }

 .text {
 width:220px;
 float:left;
 font-size:10px;
 }

 a {
 text-decoration: none;
 color: #3b5998;
 }
</style>

and including all the things together the full code will be like

<?php
header ('Content-type: text/html; charset=utf-8'); 
$limit = 5;

$group_id = '2204685680';
$url1 = 'https://graph.facebook.com/'.$group_id;
$des = json_decode(file_get_contents($url1));


echo '<pre>';
print_r($des);
echo '</pre>';


$url2 = "https://graph.facebook.com/{$group_id}/feed";
$data = json_decode(file_get_contents($url2));
?>
<style type="text/css">
 .wrapper {
 width:300px;
 border:1px solid #ccc;
 font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
 float:left;
 }

 .top {
 margin:5px;
 border-bottom:2px solid #e1e1e1;
 float: left;
 width:290px;
 }

 .single {
 margin:5px;
 border-bottom:1px dashed #e1e1e1;
 float:left;
 }

 .img {
 float:left;
 width:60px;
 text-align:center;
 margin:5px 5px 5px 0px;
 border-right:1px dashed #e1e1e1;
 }

 .text {
 width:220px;
 float:left;
 font-size:10px;
 }

 a {
 text-decoration: none;
 color: #3b5998;
 }
</style>


<div>
 <div>
 <a href='http://www.facebook.com/home.php?sk=group_<?=$group_id?>&ap=1'>
<?=$des->name?></a>
 <div style="width:100%; margin: 5px">
 <?=$des->description?>
 </div>
 </div>
 <?
 $counter = 0;
 
 foreach($data->data as $d) {
 if($counter==$limit)
 break;
 ?>
 <div>
 <div>
 <a href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
    <img border="0" alt="<?=$d->from->name?>" src="https://graph.facebook.com/<?=$d->from->id?>/picture"/>
 </a>
 </div>
 <div>
 <span style="font-weight:bold"><a href="http://facebook.com/profile.php?id=<?=$d->from->id?>">
<?=$d->from->name?></a></span><br/>
 <span style="color: #999999;">on <?=date('F j, Y H:i',strtotime($d->created_time))?></span>
 <br/>
 <?=$d->message?>
 </div>
 </div>
 <?
 $counter++;
 }
 ?>
</div>

Enjoy :)

November 1, 2010 / ranacse05

Post on Facebook Fan page as Admin

I was working on a project which needs to post feed/status on facebook fan page . Its easy and there are lots of example on web but the requirement was to post as the page admin not the user . There are lots of users on the facebook developers forum asking for this and in the doc http://developers.facebook.com/docs/reference/rest/stream.publish there is one thing enable_profile_selector but there is an easy way .

First of all you have to install the app to the fan page . So first go to the application profile which will be like http://www.facebook.com/apps/application.php?id=XXXXXXXXXXXXX, xx is the application id and click on the Add to my page , from there choose your page and click Add to page. First part done :)

Add app to fan page

Now for coding , you have to save the session key of the admin of that page. Be sure that u have the offline_access,publish_stream and manage_pages permission , manage_pages is a new kind of extended permission we need to use to post on behalf of the page admin .

Then set the session and the user id of the admin

    $facebook = new Facebook(APP_ID,APP_SECRET);
    $facebook->api_client->user = $fb_userid;
    $facebook->api_client->session_key = $session_key;

And then call the stream_publish like this


  $link = 'http://www.mylink.com/';

$attachment = array( 'name' => 'Name of the feed',
        'href' => $link,
        'description' => 'Description of the post'
);

$image_link = 'Image Link';
$attachment['media'] = array(array(
                'type'=>'image',
                'src'=>$image_link,
                'href'=>$link
));
$status = json_encode($attachment);

try {
    $facebook->api_client->stream_publish('',$status,'','',$pageid);
}
catch(Exception $e) {
    print_r($e);
}

Thats it , enjoy :)

March 28, 2010 / ranacse05

Change Background image using Twitter API

I was playing with the twitter API and i found that they allow to change the background image and color scheme using API . So i tried to change those using php.

For this test i used the cURL and php . Here is the code

<?php

set_time_limit(0);
$twitterUser = $_REQUEST['username'] ;
$twitterPass = $_REQUEST['password'] ;

$link = "http://twitter.com/account/update_profile_background_image.xml"; // The URL to change the background image

$params = array(
			"image"=>"@$fullfilepath",
			"tile"=> $tile);

//$fullfilepath is NOT the http:// path , this is the file location . Its like /home/tmp/test.jpg . But if you want to use any file from the web you need to make a copy of that file in the server then use that .

// Tile is boolean , if you want to set the background tile then this should be 'true' , it took few minutes of me because i tried with 1 , then true but it needs string true so that is 'true' or "true" . 


twitter($link,$params); // Make the call with the parameters 

function twitter($link,$params){
	global $twitterUser; // This is the username
	global $twitterPass; // Password of the user

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
	curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect:')); // Without the header you'll get 100 Error
	curl_setopt($curl, CURLOPT_URL, $link);
	curl_setopt($curl, CURLOPT_POST, 1);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
	curl_setopt($curl, CURLOPT_USERPWD, "$twitterUser:$twitterPass");
	$resp = curl_exec($curl);
	curl_close($curl);
	
	return $resp;
	}

Thats it. Have fun. :)

March 15, 2010 / ranacse05

Read mp3 tags with php

I was working on music application , so i needed a script that can read the tags from the mp3 file . Tags holds all the necessary information about the mp3 file like the song,artists,year,genre etc

Here is the script

<?php
     $mp3 = "1.mp3"; //The mp3 file.
 
     $filesize = filesize($mp3);
     $file = fopen("1.mp3", "r");

     fseek($file, -128, SEEK_END); // It reads the 
     
     $tag = fread($file, 3);
     
     if($tag == "TAG")
     {
         $data["song"] = trim(fread($file, 30));
         $data["artist"] = trim(fread($file, 30));
         $data["album"] = trim(fread($file, 30));
         $data["year"] = trim(fread($file, 4));
         $data["comment"] = trim(fread($file, 30));
         $data["genre"] = trim(fread($file, 1));
         
     }
     else
         die("MP3 file does not have any ID3 tag!");
     
     fclose($file);

     while(list($key, $value) = each($data))
     {
         print("$key: $value<br>\r\n");    
     }
 ?>    

This code will show data like this

song: If u were a sailboat
artist: Katie Melua
album: Pictures
year: 2007
comment: sumon’s collection
genre: ÿ

But to get the more information about the Genre we can add an array and change the code a bit.


$genre = array("Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge",
 "Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B",
 "Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska",
 "Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient",
 "Trip-Hop","Vocal","Jazz+Funk","Fusion","Trance","Classical",
 "Instrumental","Acid","House","Game","Sound Clip","Gospel",
 "Noise","AlternRock","Bass","Soul","Punk","Space","Meditative",
 "Instrumental Pop","Instrumental Rock","Ethnic","Gothic",
 "Darkwave","Techno-Industrial","Electronic","Pop-Folk",
 "Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta",
 "Top 40","Christian Rap","Pop/Funk","Jungle","Native American",
 "Cabaret","New Wave","Psychadelic","Rave","Showtunes","Trailer",
 "Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro",
 "Musical","Rock & Roll","Hard Rock","Folk","Folk-Rock",
 "National Folk","Swing","Fast Fusion","Bebob","Latin","Revival",
 "Celtic","Bluegrass","Avantgarde","Gothic Rock","Progressive Rock",
 "Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band",
 "Chorus","Easy Listening","Acoustic","Humour","Speech","Chanson",
 "Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus",
 "Porn Groove","Satire","Slow Jam","Club","Tango","Samba",
 "Folklore","Ballad","Power Ballad","Rhythmic Soul","Freestyle",
 "Duet","Punk Rock","Drum Solo","Acapella","Euro-House","Dance Hall");

//Change the $data['genre'] inside the if tag
$data["genre"] = $genre[ord(trim(fread($file, 1)))];

Nice hun ? Have fun .

January 13, 2010 / ranacse05

Change UI on Deactive

I was working on Adobe AIR few days ago . Honesty i liked it very much . We needed a desktop app for our web application then we were worried about the various OS and languages , then suddenly i thought about AIR . So we did it using AIR , that makes it cross-platform and easy to develop because we used HTML,CSS & JS .

So i was thinking to make the UI fade if the app is not Active but the problem is when i tested the application i saw that after deactive the UI just become fade and after 2~3 seconds its fade effect gone again !

Here is the solution .

First we have to add a new addEventListener on boot . Suppose our function is onDeactive so it’ll be like

nativeWindow.addEventListener(air.Event.ACTIVATE, onActive);
nativeWindow.addEventListener(air.Event.DEACTIVATE, onDeactive); 

the onDeactive function is here

function onActive(){
			document.getElementById('BodyWarpper').style.opacity = 1;
		}

function onDeactive(){
		if(!window.nativeWindow.active)
			document.getElementById('BodyWarpper').style.opacity = 0.8;
		}

How its working ? Actually in AIR after every second the the EventListener called . So when we make the UI deactive it called the ondeactive function and set the opacity 0.8 but then again after 1 second it call the onDeactive and onActive and if we don’t use the checking

if(!window.nativeWindow.active)

It just make the UI opacity 1 again .

Have fun !

November 25, 2009 / ranacse05

After a long time ….

Hello guys .
Its been a long time . Ok so what was i doing for this very long time ??

Here is a summery .
I was doing freelancing for more then a year . So most of the time i was very very busy .
In this time i worked with some nice guys like William (from JumpFox) and Jeff (Noobis).

After few days i joined web3dtech.com and worked there only 7 days .

And last 1st may i joined RBS and after 3 months i quit .

Then i joined Leevio , i’m still working with Leevio and i loved it very much . So this time i’m gonna stay for a long long time .

And from now i’ll try to post a new problem and solution on every week .

February 5, 2009 / ranacse05

Make timestamp more readable

Hello guys , this post for the newbie .Ofter we need to store the current time using mysql NOW() , but when later we want to print that we get 2009-02-05 19:02:49 .

But using a single line we can make that like 05 Feb, 2009 .

<?
	echo date("d M, Y",strtotime($date)); 
        // Here $date is the timestamp value from the database .
?>
	

Handy code hun ?

Follow

Get every new post delivered to your Inbox.

Join 31 other followers