How to post on user’s wall on Facebook?

Written by msnisha

Topics: Codeigniter

I want to share the source code first for the busy guys. Source code for Facebook connect for Codeigniter

Hope you have already went through my tutorial on the Facebook Connect implementation in Codeigniter. This part comes after connecting the user to your website.

Once user is authenticated with the required access tokens, you can call any methods mentioned in the Graph API at http://developers.facebook.com/docs/reference/api/. Here I will explain just one method from it to post to the user’s wall on Facebook.

In the previous tutorial we have created a Facebook connect library. Add the following method to the library it will do the trick. If user is not logged in or has no access to post then the function will return false.

function post_to_wall($message,$link="",$photourl="")
{
	if($this->fbSession)
	{
		$param = array('message'=>$message,'cb' => '');           
		if($photourl!="")
		{
			$param["picture"] = $photourl;
		}
		if($link!="")
			$param["link"] = $link;               
		$posts = $this->fb->api('/me/feed','post',$param);
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

 

Same way if you want to get user’s wall posts pass “me/home” to the fb->api method in the above functions.

Learned something? For complete reference of the available functions refer the Facebook Graph API.

11 Comments For This Post I'd Love to Hear Yours!

  1. Arvind Singh says:

    I have got this error, when i used this code.

    “Fatal error: Call to a member function api() on a non-object in /application/libraries/fb_connect.php on line 56″

    Anyone can help me to resolve this error.

  2. prajapati nilesh says:

    Hi,
    I have download your library. But not getting how to use it. ?? please let me know

  3. Patrick says:

    I tried out your tutorial for facebook connect and get redirected to facebook with an error page displayed

  4. Ariel says:

    Hi, great tutorial!

    I have a problem, i’ve downloaded your project and merge with mine.
    Everything seems to work OK, when i enter to mydomain.com/user/
    It redirects me to facebook, and ask me for the app’s permission.
    I click “Allow” and it redirects me to mydomain.com/facebook?state=………..

    But, i don’t know why, at the facebook method:

    if (!$this->fb_connect->user_id) {
    echo ‘not allowed’;
    }else{
    echo ‘allowed’;
    }

    it shows “not allowed”, but i allowed the application.

    My facebook config is ok, but i don’t know if i have to configure something on my facebook application.

    I’ll be very gratefull if you can help me.

  5. Ariel says:

    Im sorry, at the sixth line, i wanted to say:

    I click “Allow” and it redirects me to mydomain.com/user/facebook?state=………..

    i’ve missed the controller at the url

  6. nemar says:

    Hello msnisha,

    I have same problem with Ariel also, after clicked Allow, facebook redirected me to mydomain.com/user/facebook?state=…….

    How do i solve this? it doesn’t even print_r($fb_usr)

    Thanks!

    • Mickey says:

      I have got this error, when i used this code. Fatal error: Call to a member funicton api() on a non-object in /application/libraries/fb_connect.php on line 56 Anyone can help me to resolve this error.

  7. rangyu says:

    thank you very much! your source is what i want!
    but i found some errors at post_to_wall function.

    so, i modified like this,

    function post_to_wall($message,$link=”",$photourl=”")
    {
    if($this->user_id != FALSE)
    {
    $param = array(‘message’=>$message,’cb’ => ”);
    if($photourl!=”")
    $param["picture"] = $photourl;
    if($link!=”")
    $param["link"] = $link;

    $posts = $this->api(‘/me/feed’,'post’,$param);
    return TRUE;
    }
    else
    {
    return FALSE;
    }
    }

    thanks for your help!

Leave a Comment Here's Your Chance to Be Heard!