Topic-icon Rich Wall Post for offline User

Active Subscriptions:

None
13 years 10 months ago #25188 by erwvan
I would like to post to a registered user's FB wall upon occurence of a specific event.
These events are in no way related to the moments our users log on, so in most cases the user to whoms wall we need to post is not online on our site at that moment.

My question(s):

1 - Can I do a rich wall post when a user is not logged on to our site (provided he already granted us the publish_stream of course)
2 - How do I change the code to do this? Below is the code I am using now :
								$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();

							//	$post['message'] = 'is doing something';
							//	$post['message'] = JText::_('FACEBOOK_MESSAGE_SENT');
								$post['message'] = 'Congratulations!' ;
								$post['link'] = 'http://www.123blinx.com';

								if ($jfbcLibrary->getUserId()) // Check if there is a Facebook user logged in
									{
								     $jfbcLibrary->setFacebookMessage($post);
								    }
The topic has been locked.
Active Subscriptions:

None
13 years 10 months ago #25210 by erwvan
I don't want to "mess around" in the code before getting your feedback Alex, but I was thinking to do something like this :

Pass a Joomla user ID as a parameter to a new function I could add to the facebook.php file under jfbconnect/libraries :
    function getSpecificFbUserId($jUser)
    {
	   $mappedFBUserId = null;	
	   $db = JFactory::getDBO();
	   $db->setQuery($db->getQuery(true)
		   ->select("fb_user_id")
		   ->from("#__jfbconnect_user_map")
		   ->where('j_user_id = "' . $jUser .'" AND authorized= 1')
	   );
	   $mappedFBUserId = $db->loadresult();
	   	   
	   $this->set('mappedFbUserId', $mappedFbUserId);
        return $this->get('mappedFbUserId');
    }

I haven't looked through your code, but I kind of expect doing the call below will then post to that user's Facebook page, correct?
                                $jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
                                $post['message'] = 'Congratulations!' ; 
                                $post['link'] = 'http://www.123blinx.com'; 

                                if ($jfbcLibrary->getSpecificFBUserId($jUser)) // $jUser holds the Joomla! user ID of the user to whoms wall to post 
                                    { 
                                     $jfbcLibrary->setFacebookMessage($post); 
                                    }

Your thoughts?
Thank you!
The topic has been locked.
Support Specialist
13 years 10 months ago #25239 by alzander
Erwin,
Not ignoring this, just so you know. Need some time to look into exactly how to do it. With the newest v4.2.4 release, all the pieces are there as that version now fetches and stores a long-term access token for all users. That can be used for about 2 months from when they login to post to their wall (or take other actions on their part). After that, your rights would expire if they never log in again.

So, to post to the wall, you'd need to update the setFacebookMessage function to use the user's FB ID and long-term access token. However, I just want to verify that a wall post is actually what you want to do. Facebook has been pushing the use of Open Graph actions a bit, like "John read article 'xyz'" and such. Those go into the users timeline and may appear on their wall, but not guaranteed.

Wall posts definitely show on the users wall, but it also may annoy some of your users if random posts appear there.. where as Timeline "events" aren't as intrusive.

Let me know what you'd like, and we can try to come up with the code required. Open Graph actions is something that will be more a part of the next major release of JFBConnect. Actions while a user is offline would still take some custom coding though.

Hope that helps!
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 10 months ago #25249 by erwvan
Hello Alex,

In our case we indeed would like to do a Rich Wall Post.
So the only thing we need to change is to be able to post to a specific user's facebook, while that user could very well be offline at the moment we need to post.
In other words, instead of by default posting to the currently logged on users facebook, post to a different users one.

Thanks
Erwin
The topic has been locked.
Active Subscriptions:

None
13 years 10 months ago #25250 by erwvan

alzander wrote: With the newest v4.2.4 release,


Alex,
two more things:
- Is that new release going to include the change where a users profile would open in a new tab/window when his avatar is clicked?
- Is it possible to by default include the return value on a setFacebookMessage call? This way we can take different actions depending on whether or not the post was successful, and even discriminate depending on the public the post was made to (public, friends, private,...)

Thanks
Erwin
The topic has been locked.
Active Subscriptions:

None
13 years 10 months ago #25327 by erwvan
- friendly bump

Alex,
Any updates on posting to the wall of an offline user?

Thank you
Erwin
The topic has been locked.
Support Specialist
13 years 10 months ago #25354 by alzander
Erwin,
Sorry for the delay. First off, answer to the easy questions:
* Yes, the new JFBConnect release has links from avatars open their profile in a new window
* You can change the setFacebookMessage call to return the $response variable at the end very easily. It won't break anything on our end.

As for the update to the setFacebookMessage function, here's roughly what I think it will take. This has not been tested. Feel free to try it and let us know what happens or if there are any issues:
function setFacebookMessage($message, $jUserId = null)
    {
        $response = false;
        if ($message)
        {
            try
            {
		if ($jUserId)
		{
        		$userMapModel = new JFBConnectModelUserMap();
			$userInfo = $userMapModel->getData($jUserId);
			$fbUserId = $userInfo->fb_user_id;
			if (!$fbUserId)
				return $response;
			$message['access_token'] = $userInfo->access_token;
		}
		else
		        $fbUserId = 'me';

                $currentMessage = '';

                $response = $this->api('/' . $fbUserId . '/feed');
                if (isset($response['data'][0]))
                    $currentMessage = $response['data'][0]['message'];

                if ($currentMessage != $message['message'])
                {
                    if (is_array($message))
                        $response = $this->api('/' . $fbUserId . '/feed', $message);
                    else
                        $response = $this->api('/' . $fbUserId . '/feed', array('message' => $message));
                }
            } 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
                */
            }
        }
        return $response;
    }
Then, just call it like:
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
$post['message'] = 'Congratulations!' ; 
$post['link'] = 'http://www.123blinx.com'; 

$respone = $jfbcLibrary->setFacebookMessage($post, $jUserId);
If the Joomla User doesn't have a link to a Facebook account, you'll get a false back. Otherwise, the response will be returned from Facebook, whatever that is, good or bad.

Again, untested completely, but please let us know how it goes. We'll likely add this (or something similar) to the next release as it's nice, easy functionality to have!

Thanks,
Alex
The topic has been locked.