Topic-icon setFacebookMessage return values

Active Subscriptions:

None
13 years 11 months ago #24058 by erwvan
Hello!

Can I , based on the return value of setFacebookMessage see whether or not the post on a user's wall actually went through or failed?
Ideally I would even want to see if it was posted and available to public, friends or just the user...

Thank you
Erwin
The topic has been locked.
Active Subscriptions:

None
13 years 11 months ago #24216 by erwvan
friendly bump.
Any help on this one?
The topic has been locked.
Support Specialist
13 years 11 months ago #24222 by alzander
Erwin,
Sorry for the delay. If you look at the /components/com_jfbconnect/libraries/facebook.php file, you'll find the setFacebookMessage function. In there, if you check the $response (or add a return statement so you can see it wherever you're calling that function), if it's null, the message wasn't posted. That can be for a few reasons (no permission, duplicate post, etc). Otherwise, it will return the post ID for the message, like:
1251253607_3367648150606
You can then make additional Facebook calls to get information about that post to see where it was posted and with what privacy settings. You can test what that info looks like in the Graph Explorer, below:
developers.facebook.com/tools/explorer

Simply use the Get Access Token button, set your permissions to read_stream and then put in that ID. You'll see all the available info. If you think you can code up something to parse out what you need, we can gladly help you get that information using the JFBConnect API.

Hope that helps, and sorry again for the delay!
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 11 months ago #24269 by erwvan
Hello Alex,

So if I understand correctly I need to "hack" your code, and in the facebook.php file I should have this :
    function setFacebookMessage($message)
    {
        if ($message)
        {
            try
            {
                $currentMessage = '';

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

                if ($currentMessage != $message['message'])
                {
                    if (is_array($message))
                        $response = $this->api('/me/feed', $message);
                    else
                        $response = $this->api('/me/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;
        }
    }

That way I can use the return code i my calling function, correct?

Thank you
Erwin
The topic has been locked.
Support Specialist
13 years 11 months ago #24285 by alzander
Yeah, that should do it, but I'd recommend the following changes:
* At the top, add $response = null (that will make it so the value is always initialized before being returned):
function setFacebookMessage($message) 
    {
          $response = null;
* Move the return $response to right before the very last } (not before the 2nd to last). That will ensure that something is always returned... either null or the ID of the actual post.

None of those are critical, but it makes for cleaner code.

Hope that helps,
Alex
The topic has been locked.