Question

Well I've tried to find something on the new Facebook PHP SDK V4 to see if anyone else is having issues and according to some tutorial comments there have been many complaints to Facebook Developers site about the new SDK but will see if anyone here has found a way around it.

So I've set up my new Facebook App the same way I set up any other app in the past. I have my App ID and Secret and have set up my index.php page as follows:-

<?php

session_start();
require_once('Facebook/FacebookSession.php');
require_once('Facebook/FacebookCanvasLoginHelper.php');
require_once('Facebook/FacebookRedirectLoginHelper.php');
require_once('Facebook/FacebookRequest.php');
require_once('Facebook/FacebookResponse.php');
require_once('Facebook/FacebookSDKException.php');
require_once('Facebook/FacebookRequestException.php');
require_once('Facebook/FacebookAuthorizationException.php');
require_once('Facebook/GraphObject.php');
require_once('Facebook/GraphUser.php');
require_once('Facebook/GraphSessionInfo.php');

use Facebook\FacebookSession;
use Facebook\FacebookCanvasLoginHelper;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;
use Facebook\GraphSessionInfo;

$app_id = '..........';
$app_secret = '...........';

FacebookSession::setDefaultApplication($app_id, $app_secret);

$helper = new FacebookCanvasLoginHelper();

try {
$session = $helper->getSession();
} catch (Exception $e) {
echo 'Error: '.$e->getMessage();
}

if ($session) {
//$_SESSION['token'] = $session->getToken();
echo 'Logged In!';
try {
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graph = $response->getGraphObject();
    echo 'Hi '.$graph->getProperty('name');
} catch (FacebookRequestException $e) {
    echo $e->getMessage();
} 
}
else {
//echo '<a href="'.$helper->getLoginUrl().'">Login</a>';
$helper = new FacebookRedirectLoginHelper('https://apps.facebook.com/event-lister');
$auth_url = $helper->getLoginUrl(array('email', 'user_friends'));
echo '<script>window.top.location.href="'.$auth_url.'"></script>';
}
?>

Apologies for pasting everything in but had to make sure I was thorough in there being everything that was needed in the index.php file.

This produces a blank page and doesn't even offer the opportunity to log in. I've followed two tutorials with no success and the Facebook App has been configured correctly with the correct canvas URL etc... in place

Please can someone let me know if they have had the same issues and if so how did you overcome them or is it an on going thing that Facebook know about and are busy trying to fix? Or have I gone wrong somewhere?

Was it helpful?

Solution

I have had issues like this with the API. If it is a blank page most likely it is an error in your PHP. Enable error reporting by putting this at the top of the page on any page that is being loaded.

<?php
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
?>

Also since a lot of people were having problems with the FB api login script. I made one detailing a few lines of code to change to get it up and running. I also included a copy of the V4 FBapi. Just get it off the github page and follow the readme instructions and you will be up and running in 5 minutes.

Click Here

You will also find an example of making api calls to gain information about the user and returning to an array. You can easily build on to this array with any data you may need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top