× Joomla Facebook Connect support forum

Topic-icon Fatal error: class 'Facebook' not found - PHP

Active Subscriptions:

None
I had JFBConnect installed and it did work for a long time. Connecting through facebook still works like a charm, but I used some functions in other components, with help from someone who knows a lot of PHP. I did update jfbconnect, no solution...
So we implanted a function in seminar for joomla so when a user registers for an event, this is mentioned on facebook.
In seminar it looks like this:
require_once (JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'helpers'.DS.'facebookhelper.php');

		// Caption voorbeeld: '{*actor*} rated the lolcat 5 stars' 
		$message = "gaat naar " . $row->title;
		$caption = "op " . date("d-m-Y", strtotime($row->begin));
		$description = $row->shortdesc;
		$url = "http://www.jozib.be/index.php?option=com_seminar&task=3&cid={$cid}&Itemid=68";
    $action_links = array( array('text' => 'Go Jozib', 'href' => "http://www.jozib.be"));		
    $image_url = $row->image ? ("http://www.jozib.be/images/stories/seminar/" . $row->image) : null;
		
		JFBConnectFacebookHelper::setWallMessage($message, $caption, $description, $url, $action_links, $image_url); 
  }

when this function is used i got this error:
Fatal error: Class 'Facebook' not found in /customers/jozib.be/jozib.be/httpd.www/components/com_jfbconnect/helpers/facebookhelper.php on line 144

facebookhelper.php code on line 144:
function getFbLib()
	{
		if (self::$_FbRoot == null)
		{
			include_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jfbconnect'.DS.'assets'.DS.'facebook-api'.DS.'facebook.php');
			$configModel = self::getConfigModel();
			$facebookApiKey = $configModel->getSetting('facebook_api_key');
			$facebookSecretKey = $configModel->getSetting('facebook_secret_key');
			#echo "FBH. pre root user : ".self::$_OrigFbUser."";
			[b]self::$_FbRoot = new Facebook($facebookApiKey, $facebookSecretKey);[/b]
			self::$_OrigFbUser = self::$_FbRoot->user;
			#echo "Key: ".self::$_FbRoot->api_client->session_key;
			self::$_OrigFbSessionKey = self::$_FbRoot->api_client->session_key;
			#echo "FBH. post root user : ".self::$_OrigFbUser."";
		}
		return self::$_FbRoot;
	}

We added this in facebookhelper.php:
function setWallMessage($message, $caption, $description, $url, $action_links = null, $image_url = null)
  {
    try
    {
      $fbClient = self::getFbClient(false);

      if($fbClient->users_hasAppPermission("publish_stream"))
      {
        //$attachment = array('name' => $message, 'href' => $url);
        $attachments = array();
        if ($caption)
        {
          $attachment['caption'] = $caption;
        }
        if ($description)
        {
          $attachment['description'] = $description;
        }
        if ($image_url)
        {
          $attachment['media'] = array(array('type' => 'image', 'src' => $image_url, 'href' => $url));
        }
        
        $attachment = json_encode($attachment);
        $action_links = json_encode($action_links); 
        
        $fbClient->stream_publish($message, $attachment, $action_links, null);
      }
    }

I don't see where the function getFbLib is called, I don't see what went wrong, I don't see the function Facebook... I'm pretty confused.

anyone?
The topic has been locked.
Support Specialist
15 years 2 months ago #8331 by alzander
Glad to see you upgraded! It looks like you were using JFBConnect 2.x before. The new version (3.x) is much easier to do what you're looking for, and has much cleaner code.

To do what you were doing before, try the following:
$wallPost = array();
$wallPost['message] = $message;
if ($description)
  $wallPost['description'] = $description; 
if (any other values)...
  $wallPost['otherValues'] = $otherValue;
require_once (JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'libraries'.DS.'facebook.php'); 
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
if ($jfbcLibrary->getUserId()) // Check if Facebook thinks there's a user logged in
   $jfbcLibrary->setFacebookMessage($wallPost);

All the possible values are described in the link below. The names may have changed from what you were using, but all the same functionality should be there.
developers.facebook.com/docs/reference/api/post/

Hope this helps.. but if you run into issues, let us know!
The topic has been locked.
Active Subscriptions:

None
15 years 2 months ago #8333 by boodschap
Hey Alex,

thanks for your reply! I'm really getting into the new code now!
So I did implement the setFacebookMessage in my seminar-component and it works. When someone registers for an event it will be displayed on his facebookwall.

Now, we made the new function so other information was also displayed, not only $message, also: $caption, $description, $url, $action_links = null, $image_url = null. I did send these values to setFacebookMessage, but I'm not really getting it there to work. If you have a quick solution... my php is not that good :-)

in the meantime I keep on trying

our code:
function setWallMessage($message, $caption, $description, $url, $action_links = null, $image_url = null)
  {
    try
    {
      $fbClient = self::getFbClient(false);

      //$attachment = array('name' => $message, 'href' => $url);
        $attachments = array();
        if ($caption)
        {
          $attachment['caption'] = $caption;
        }
        if ($description)
        {
          $attachment['description'] = $description;
        }
        if ($image_url)
        {
          $attachment['media'] = array(array('type' => 'image', 'src' => $image_url, 'href' => $url));
        }
        
        $attachment = json_encode($attachment);
        $action_links = json_encode($action_links); 
        
        $fbClient->publish_stream($message, $attachment, $action_links, null);
      }
    catch (FacebookRestClientException $e)
    {
      /*
        Fatal error: Uncaught exception 'FacebookRestClientException' with message 
        'Updating status requires the extended permission status_update' in 
        .../com_jfbconnect/assets/facebook-api/facebookapi_php5_restlib.php:3007
      */
    }
  }
The topic has been locked.
Active Subscriptions:

None
15 years 2 months ago #8334 by boodschap
So what I'm trying to do now is sending the other values besides $message to the facebookwall.
Altering setfacebookmessage doesn't bring any luck yet:
function setFacebookMessage($message, $caption, $description, $url, $action_links = null, $image_url = null)
    {
        if ($message)
        
		if ($image_url)
        {
          $attachment['media'] = array(array('type' => 'image', 'src' => $image_url, 'href' => $url));
        }
        
        $attachment = json_encode($attachment);
        $action_links = json_encode($action_links); 
		
		{
            try
            {
                if (is_array($message))
                    $response = $this->api('/me/feed', $message, $attachment, $action_links, null);
                else
                    $response = $this->api('/me/feed', array('message' => $message, $attachment, $action_links, null));
            }
            catch (JFBCFacebookApiException $e)
            {
                /*
                  Fatal error: Uncaught exception 'FacebookRestClientException' with message
                  'Updating status requires the extended permission status_update' in
                  .../com_jfbconnect/assets/facebook-api/facebookapi_php5_restlib.php:3007
                 */
            }
        }
    }
The topic has been locked.
Support Specialist
15 years 2 months ago #8339 by alzander
The code I posted above should take care of these extra values. Mainly, look at the variable $wallPost. You want to set any extra values in this array, and the setFacebookMessage function will automatically set them. You shouldn't modify that function at all to accomplish what you're looking for.

Although the function call has an input parameter of $message, if it's passed as an array, all those values are used. Hope that makes sense, but basically, what you should be building up to pass into the setFacebookMessage should look something like:
if ($description) 
  $wallPost['description'] = $description; 
if (any other values)... 
  $wallPost['otherValues'] = $otherValue;

We're using that function (I believe just how it is) in 3.2 (coming out later this month) to post images and links to the user's wall when they login or register, if configured that way.. so you should be able to use that functionality now with your custom code.

Good luck!
The topic has been locked.
Active Subscriptions:

None
15 years 2 months ago #8346 by boodschap
Now I see how it's build-up.
I got this code now, the message gets displayed, the rest of it doesn't, am I using the wrong variables?
$wallPost = array(); 
	
		$wallPost['message'] = "gaat naar " . $row->title;
		$wallPost['description'] = $row->shortdesc;;
		$wallPost['caption'] = "op " . date("d-m-Y", strtotime($row->begin));
		$wallPost['url'] = "http://www.jozib.be/index.php?option=com_seminar&task=3&cid={$cid}&Itemid=68";
		$wallPost['image_url'] = $row->image ? ("http://www.jozib.be/images/stories/seminar/" . $row->image) : null;
		$wallPost['action_links'] = array( array('text' => 'Go Jozib', 'href' => "http://www.jozib.be"));
		
	require_once (JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'libraries'.DS.'facebook.php'); 
	$jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
	if ($jfbcLibrary->getUserId()) // Check if Facebook thinks there's a user logged in 
	   $jfbcLibrary->setFacebookMessage($wallPost);
The topic has been locked.
Support Specialist
15 years 2 months ago #8349 by alzander
Yeah, the parameters are renamed a bit. Look at the URL below, and scroll down about half-way to the "Publishing" section and you can see the updated and available parameters. For example, instead of 'url' it should be 'link'.
developers.facebook.com/docs/reference/api/post/

Hope that helps, but let us know if you have other issues. Very glad you decided to subscribe to the latest version! Now that you've used JFBConnect and tested our support a bit, if you feel we're worthy of it, we'd love for you to vote or review us on the Joomla Extension Directory. There's a link in our signature should you be interested in helping out.
The topic has been locked.
Active Subscriptions:

None
15 years 2 months ago #8360 by boodschap
Finally got it right! It might have been a lot easier if I really knew PHP :-)
$wallPost = array('message' => "gaat naar " . $row->title,
'caption' => "op " . date("d-m-Y", strtotime($row->begin)),
'link' => "http://www.jozib.be/index.php?option=com_seminar&task=3&cid={$cid}&Itemid=68",
'description' => $row->shortdesc,
'picture' => $row->image ? ("http://www.jozib.be/images/stories/seminar/" . $row->image) : null,
'actions' => array(array('name' => 'Go Jozib', 'link' => "http://www.jozib.be")));

    require_once (JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'libraries'.DS.'facebook.php'); 
    $jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
    if ($jfbcLibrary->getUserId()) // Check if Facebook thinks there's a user logged in 
       $jfbcLibrary->setFacebookMessage($wallPost);
The topic has been locked.
Active Subscriptions:

None
15 years 2 months ago #8361 by boodschap
Thanks a lot Alex!
The topic has been locked.
Support Specialist
15 years 2 months ago #8373 by alzander
No problem Maarten! Really glad you got it going, and happy we could help.

Should you need anything else, just let us know :)
The topic has been locked.