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
Related
I have on my generic sign in page a button that allows a user to log in via facebook. Also, i have the following code just prior to the user clicking the button so i can pass a redirect url to the callback after oauth2 authorization and redirect the logged in user somewhere.
<?php
session_start();
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed
$fb = new \Facebook\Facebook([
'app_id' => 'appid',
'app_secret' => 'appsecret',
'default_graph_version' => 'v2.10',
]);
$helper = $fb->getRedirectLoginHelper();
$url=$helper->getLoginUrl("https://example.com/fblogin/callback");
$_SESSION['redirect']='somehurl';
setcookie("redirect","example.com");
header("Location: $url&scope=email");
Then I have
In my callback I have
<?php
session_start();
var_dump($_SESSION['redirect']); //null
var_dump($_COOKIE['redirect']); // null
I dont understand why but facebook is destroying my cookie and session data. Im using version 2.10
Very new to php and I am trying to figure out how to use Facebook-PHP-SDK. I set up an account on Facebook Developers and am trying to get data from my own Facebook, which I have linked to my developer account. I am trying to implement the following practice code but I am confused about the login URL. Am I suppose to put my own Facebook URL for that? Or something else?
Practice Code
session_start();
$fb = new Facebook\Facebook([
'app_id' => '{app-id}', // Replace {app-id} with your app id
'app_secret' => '{app-secret}',
'default_graph_version' => 'v3.3',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email']; // Optional permissions
$loginUrl = $helper->getLoginUrl('https://example.com/fb-callback.php', $permissions);
echo 'Log in with Facebook!';
You should put in the login url the link of the file content your code:
example, this mean the file who contains the current code:
$loginUrl = "http://localhost/login.php"
and the https://example.com/fb-callback.php must redirect to a (file/url) in your application to verify the authentication and extract the access token for example.
i have making Facebook signup in php.when i cliked on Facebook login btn they show me this error "Insecure Login Blocked: You can't get an access token or log in to this app from an insecure page. Try re-loading the page as https://"
this is config.php file code
<?php
session_start();
require_once "Facebook/autoload.php";
$FB = new \Facebook\Facebook([
'app_id' => '571388466554956',
'app_secret' => '8381c3ba6df5f1d44ab8643be299e8dd',
'default_graph_version' => 'v2.10'
]);
$helper = $FB->getRedirectLoginHelper();
?>
OK The first step I think is to download the latest version of the Facebook SDK. Local tests showed this to me.
I am revamping the attachment of our Page Tab app using the "Add Page Tab", and am a little unsure about the flow. This is what I'm trying to do:
1) direct our users to the Add Page Tab dialog with our appId (works)
2) our redirect URL is hit with a post that has the "tabs_added" parameter
3) I use this code to try and get information about the FB account that is getting to my app:
$this->fb = new Facebook\Facebook([
'app_id' => <app_id>,
'app_secret' <app secret>,
'default_graph_version' => 'v2.9'
]);
$tabs_added = PARAM('tabs_added');
If I get a 'tabs_added' parameter, I'm assuming that means someone is "attaching" my app to their page, and I want to get information (specifically UID) for their account:
$helper = $this->fb->getPageTabHelper();
$signedRequest = $helper->getSignedRequest();
This call returns nothing
$parsed_signed_request = FacebookSignedRequest::parse_signed_request( $signedRequest, <app secret> );
This call fails because there is no signed request.
What am I missing? I am using v5 of the Facebook PHP API.
thanks
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