I have been trying for hours now to log a user out of Facebook.com using the official php sdk V2.4 (https://github.com/facebook/facebook-php-sdk-v4/) and api endpoint version V2.5.
What I found until now is that I should use
$facebook->destroySession();
However this function is not available if I use
$facebook = new Facebook\Facebook([
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => 'v2.5',
]);
So instead I used
$helper = $facebook ->getRedirectLoginHelper();
$logoutUrl = $helper->getLogoutUrl($user['facebookAccessToken'], 'www.mypage.com');
This returns
$logoutUrl = https://www.facebook.com/logout.php?next=www.mypage.com&access_token=facebookToken
I checked the token and it is correct. However when I redirect to $logoutUrl then facebook does not logout the user but instead redirects to https://www.facebook.com/home.php while the user is still logged in.
I guess that this is due to the new version V2.5? Is there any way to accomplish this task with the new version?
Thanks a lot in advance!
Ok nevermind, I found out why it didn't work. The problem was that I used xampp on my localhost to debug it. But the redirect link was set to the homepage. After I changed the redirect link to the localhost address it was working.
Hope this helps, if anyone else ever struggles with this.
Cheers
Related
I have found few topics about this issue here, but nothing helped me yet. This is my first time when I try to implement facebook login to my website (using PHP). I've found some tutorial, went through all the steps and when I wanted to try login, I got error “Error: Can’t Load URL: The domain of this URL isn’t included in the app’s domains”. Here are screenshots of my settings at FB apps manager:
Even when I try to paste redirect URL into their validator, everything seems fine.
public function getFbLoginUrl()
{
$fb = new Facebook(array(
'app_id' => '434864033760844',
'app_secret' => '<app secret>',
'default_graph_version' => 'v3.2',
));
$helper = $fb->getRedirectLoginHelper();
$helper->getAccessToken('https://vinoservis.mobydyk.cz/sign/facebook');
$permissions = []; // Optional permissions
$loginURL = $helper->getLoginUrl('https://vinoservis.mobydyk.cz/sign/facebook', $permissions);
return $loginURL;
}
I am using PHP SDK for creating facebook login, which works fine but when I want to logout and I use getLogoutUrl method which returns logout url in this form:
https://www.facebook.com/logout?next=google.com&access_token=my_access_token
After I redirect to this page I get to the This page is not avalible page on FB and I am not logged out. Any idea what could be wrong ? or it will be SDK bug ? thanks.
I have created a article for facebook login logout with graph api with php. You can see the following code for logout from facebook with php. This is code for logout.php
session_start();
if(isset($_SESSION['fb_access_token'])){
require_once 'php-graph-sdk-5.5/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'app-id', // Replace {app-id} with your app id
'app_secret' => 'app-id-secret',
'default_graph_version' => 'v2.4',
]);
$url = 'https://www.facebook.com/logout.php?next=your-website-return-url/&access_token='.$_SESSION['fb_access_token'];
session_destroy();
header('Location: '.$url);
}
If you need full source code then you can see this link
I've been including the "login with Facebook" product which allows you to get users information based on their Facebook's account email.
So when I try to redirect after the users accept my app on Facebook, it redirects to my homepage, not to the redirect URL I specified on the getLoginUrl() method.
My code is as follows:
$fb = new Facebook([
'app_id' => "my app id",
'app_secret' => "my secret",
'default_graph_version' => 'v2.2'
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email'];
$loginUrl = $helper ->getLoginUrl('http://127.0.0.2/alumn-e/pages/facebookcallback/', $permissions);
$this->set('urlfacebook',$loginUrl);
These are my allowed redirection URIs:
For some reason my users are redirected to http://127.0.0.2/alumn-e/#_=_ when they accept the conditions on the use of my app, when I was expecting to get a redirection to http://127.0.0.2/alumn-e/pages/facebookcallback/.
I've been searching on google lots of time and I can't understand why.
EDIT: I've included error_reporting on my function and I've done the process of logging on fb and it doesn't show anything on the console.
I discovered this was a mistake on my facebook callback function so thanks to everyone! I finally understood this and I used v2.8 finally.
I'm admin of a page and I have my app with ID and Secret.
When I go to Graph api Explorer I can easily take my User Access Token with permission "manage-pages".
I need to take the same via php, using the FB sdk 3.2.
I managed to run only this:
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'My app ID',
'secret' => 'My app secret',
));
//This token is: "My app ID|My app secret"
print_r($facebook->getAccessToken());
How Can I get the user access token with permission via php with fb sdk 3.2?
Can somebody help me? Thank you!
You need to generate a Login URL and redirect Users to that one, it´s explained in the docs for 3.x.x: https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/
With manage_pages, it would be like this:
$params = array(
'scope' => 'manage_pages',
'redirect_uri' => 'https://www.myapp.com/post_login_page'
);
$loginUrl = $facebook->getLoginUrl($params);
I highly suggest upgrading to a server with PHP 5.4+ though.
You shouldn't waste your time with using an outdated version of the PHP SDK, or is there a reason why you chose the old version?
See
https://developers.facebook.com/docs/php/gettingstarted/4.0.0
on how to implement Facebook Login.
first facebook asks me to click okay to authorize the app then chrome gives me this error. and the I have this endless redirect problem. I have read many cases about this but none clear and simple enough to get me over this obstacle.
The webpage at __________&redirect_uri=http%3A%2F%2Fmizu.net46.net%2Ffacebookpost6.php&state=_________________&sdk=php-sdk-3.2.3&req_perms=user_status%2Cpublish_stream%2Cuser_photos%2Coffline_access%2Cmanage_pages#=">https://www.facebook.com/dialog/oauth?client_id=__________&redirect_uri=http%3A%2F%2Fmizu.net46.net%2Ffacebookpost6.php&state=_________________&sdk=php-sdk-3.2.3&req_perms=user_status%2Cpublish_stream%2Cuser_photos%2Coffline_access%2Cmanage_pages#= has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
what I know.
facebook.php is working
the secret and appid are being passed correctly by the script.
I must have configured my app settings on the facebook development site almost correctly
how do I know this?
because when I change those variables in my script or adjust the settings
on facebook development server, I dont even get this far, I dont get asked to click ok or see my facebook profile in chrome.
what I dont know.
How to fix this redirect problem. or complete the authentication process. echo $user always returns 0.
my code looks like this:
require 'src/facebook.php';
$app_id = "xxxxxxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxx";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
echo $user;
if(($facebook->getUser())==0)
{
header("Location:{$facebook->getLoginUrl(array('req_perms' =>
'user_status,publish_stream,user_photos,offline_access,manage_pages'))}");
exit;
}
thanks for any help
changing the setting to no when asked" is this a desktop app? " in the advanced section of app configuration on developers.facebook.com seem to resolve this issue.