0

I created a Facebook App using PHP on my website. To use this application on my website the user must login using Facebook authentication.

This app basically lets the user post a default comment on his wall. It works fine using my facebook profile account, but when I asked my friend to use my site he gets the following error - 'Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in'

The only solution to my problem i found till now is by entering the following URL -

https://www.facebook.com/login.php?api_key=API_KEY&cancel_url=http://www.magimagi.com&next=http://magimagi.com/login/uploadtopage2.php&fbconnect=1&return_session=1&session_version=3&v=1.0&display=page&req_perms=user_about_me,user_birthday,publish_stream,offline_access

I do not want to create a link on my app for the user to click it - instead I want it integrated into the PHP code already on my website.

Here is a sample PHP code I have

/ Get User ID
$user = $facebook->getUser();

if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl(   array(
'scope' => 'publish_stream'
));
}

This is the HTML

<form id="selectFriend" name="selectFriend" method="post">
<label for="Friend">Friend:</label>
<select id="friend" name="friend">
<?php 
foreach($user_friends['data'] as $f){
echo '<option value="'.$f['id'].'">'.$f['name'] .'</option>';
} 
?>
</select>
<label for="URL">URL:</label>
<input id="link" name="link">
<input id="message" name="message">
<input type="submit" name="submit" id="submit" value="Send!">

I read almost all the documentation there is etc... but unfortunately I didn't manage.

I am wondering why using my profile it is working while it is not working on others' profile.

I am still a beginner so please save your insults!

1 Answers1

0

Your code is way out of date as far as I can see - the parameters you're using in the call to the Auth Dialog (specifically req_perms) were deprecated in October 2011 - the current (manual) method of redirecting to the auth dialog is:

https://www.facebook.com/dialog/oauth?
    client_id=YOUR_APP_ID
   &redirect_uri=YOUR_REDIRECT_URI
   &scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
   &state=SOME_ARBITRARY_BUT_UNIQUE_STRING

The getLoginUrl() method of the PHP SDK will send users there, and when your code processes the code returned it'll get an access_token which can be used to make calls on behalf of a user

See https://developers.facebook.com/docs/authentication/server-side/ for the full server side flow

Igy
  • 43,710
  • 8
  • 89
  • 115