Reputation: 2018
I have this code from my facebook web app:
<?php if (!$user_profile) { ?>
<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
$data = array("message" => "Hello Woghfd!");
$status = $facebook->api("/me/feed", "POST", $data);
//echo $user;
?>
<?php }
I have this code, a simple thing to post to a users wall. I know that I need the permission for this of publish_stream, so ive included this in the button (at the top) but when a user visits my site they get the error:
Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action
Now when the user logs out of facebook via facebook, and then logs in using my login button, it works ok, but how can I set this up so it dioesnt show this error when first visiting the site??? So confusing!
thanks :)
Upvotes: 0
Views: 488
Reputation: 35900
Your if statement doesn't check if the user has authenticated with the app:
if (!$user_profile)
To check if the user has authenticated, do something like this:
try {
$fb_userid = $facebook->getUser();
// user is authenticated continue normally...
} catch (FacebookApiException $e) {
// user is not authenticated, do something else...
}
Upvotes: 1