I have the following code:
<?php if (!$user) { ?>
<div class="fb-login-button" data-perms="email,user_birthday,publish_stream">Login with Facebook</div>
<?php } else { ?>
Your user profile is
<pre>
<?php //print htmlspecialchars(print_r($user_profile, true)) ?>
</pre>
<?php echo $user_profile['name']; ?>
<?php
try{
$data = array("message" => "Hello Woghfd!");
$status = $facebook->api("/me/feed", "POST", $data);
}catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl( array(
'scope' => 'publish_stream'
));
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
?>
<?php }
I am using both JS and PHP SDK's... JS to log the users in, and PHP to get their info (experimental at the moment). My problem is that I have used the PHP to POST the data to the users FB feed, and it kept throwing an error if the user wasnt logged in.
I have solved the problem by using a try catch scenario to try and send the data to facebook, but if it fails, instead of throwing an error, it just asks the user to login with the PHP getLoginUrl finction.
Is this the best way to go about doing this? Or would you usually wrap this POST to feed functionallity in a onClick function or something?
Just asking because I think Im getting to grips with the whole thing and need to know if I am going in the right direction.
Thanks :)