no access token or session initiated when passing user through $facebook->getLoginUrl();

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


no access token or session initiated when passing user through $facebook->getLoginUrl();



I have run the php sdk example from Facebook and it runs fine on my server but when I dropped the code into a method of codeigniters controller it doesn't return a session at all - has anyone experienced this?



Even thought it has been authenticated and the user has accepted the application I failed to get a session back- the only thing that is in the session is


[fb_32567534414789_state] => 3d34472df552ad7fef1911d2f97122f0



Even the url parameters are being passed back from Facebook - both state and code have values.



The problem is that it runs fine and without issue in a standalone example but when I bring it into controller method it doesnt work.



I have commented out every line in my controllers constructor and its method. Then only listing the example code with a model method to pull the api key/secret from the db; And it doesn't work;



I recently upgraded to the latest sdk - I'm stuck and do not know what to do.



update



i have added two examples to my server to show how its operating



this is the standard sdk example in a controller method of a brand new codeigniter install (with the latest sdk pulled from github)



https://beta.exceleratedsolutions.com/testfb/welcome/testfb/



this is the standard sdk example



https://beta.exceleratedsolutions.com/testfb/examples/example.php



code listing


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
*
* Licensed under the Academic Free License version 3.0
*
* This source file is subject to the Academic Free License (AFL 3.0) that is
* bundled with this package in the files license_afl.txt / license_afl.rst.
* It is also available through the world wide web at this URL:
* http://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to obtain it
* through the world wide web, please send an email to
* licensing@ellislab.com so we can send you a copy immediately.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
* @license http://opensource.org/licenses/AFL-3.0 Academic Free License (AFL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/

class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
}

/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->view('welcome_message');
}

public function testfb(){

$this->load->helper('facebook');

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '325675344144789',
'secret' => 'xxxxxxxxxxx',
));

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

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}

// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}

// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');

?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>php-sdk</title>
<style>
body {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
}
h1 a {
text-decoration: none;
color: #3b5998;
}
h1 a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>php-sdk</h1>

<?php if ($user): ?>
<a href="<?php echo $logoutUrl; ?>">Logout</a>
<?php else: ?>
<div>
Login using OAuth 2.0 handled by the PHP SDK:
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
</div>
<?php endif ?>

<h3>PHP Session</h3>
<pre><?php print_r($_SESSION); ?></pre>

<?php if ($user): ?>
<h3>You</h3>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture">

<h3>Your User Object (/me)</h3>
<pre><?php print_r($user_profile); ?></pre>
<?php else: ?>
<strong><em>You are not Connected.</em></strong>
<?php endif ?>

<h3>Public profile of Naitik</h3>
<img src="https://graph.facebook.com/naitik/picture">
<?php echo $naitik['name']; ?>
</body>
</html>

<?php
}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>



as you see- this is just standard



i have pushed this to pagodabox with the same issue




2 Answers
2



It could be because you have initiated a session elsewhere in your code if you are using session management of some kind.



You could try put the Facebook php-sdk into library folder instead of helper. Also, you might follow this tutorial, it worked for me, maybe you're not setting some needed configurations (steps 1 to 5), also check the end of the tutorial for May 3rd Update:



http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/



Regards





if its running on the same server it doesnt explain how codeigntier fails with it
– Chris Mccabe
Feb 13 '12 at 0:50





I don't understand you.
– Isaac Zepeda
Feb 13 '12 at 0:56






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name