Jump to content

Facebook API help


magic2goodil

Recommended Posts

I posted about this code a minute ago, it works now, but is not passing the key and next variables to the address bar when it takes you to facebook's login...Can anyone tell me what I did wrong in this code?

[code]<?php

class cbx_facebookAPI {

// ### Class Variables

var $config; // array to hold API variables
var $facebook; // holds Facebook object
var $session; // holds Facebook session
var $user_info; // array to hold Facebook User Info before fix
var $user; // array to hold fixed user information


// ### cbx_facebookAPI class construct ###

function __construct() {


// ### Registered API Variables ###

$this->config = array();
$this->config['api_key'] = "fab265688ad5a13ec15b61477e2f0afd";
$this->config['secret'] = "***********";
$this->config['next'] = 'index.php';

} // ### End __construct() ###


// ### Make Connection and Pull User Info from Facebook ###

function doConnect() {



                // ##### INCLUDE CLASS #####

include('facebook.php');


if (!empty($_REQUEST['auth_token'])) {

// ##### INITIATE FACEBOOK CLASS #####

$this->facebook = new Facebook ($this->config['api_key'], $this->config['secret'], null, false, false, false);

// ##### SET SESSION INFORMATION #####

$this->session = $this->facebook->auth_getSession ($_REQUEST['auth_token']);

// ##### SET COOKIES #####

setcookie('facebook_session_key', $this->session[0]['elements'][0]['text']);
setcookie('facebook_uid', $this->session[0]['elements'][1]['text'], time()+60*60*24);

// ##### REDIREC TO CHAT #####

header('Location: ' . $_SERVER['PHP_SELF']);
} // End IF



else {

// ##### CHECK FOR USER LOGGED IN #####

if (empty($_COOKIE['facebook_session_key'])) {

// ##### REQUIRE LOGIN #####

header('Location: http://api.facebook.com/login.php?api_key=' . $this->config['api_key'] . '&next=' . $this->config['next']);
} // End IF

// ##### INITIATE CLASS #####

$this->facebook = new Facebook ($this->config['api_key'], $this->config['secret'], $_COOKIE['facebook_session_key']);

// ##### PULL USER INFO #####

$this->user_info = $this->facebook->users_getInfo ($_COOKIE['facebook_uid'], 'first_name,last_name,current_location,affiliations');

$this->user = array();
$this->user['firstname'] = $this->user_info[0]['elements'][0]['elements'][0]['text'];
$this->user['lastname'] = $this->user_info[0]['elements'][0]['elements'][1]['text'];


// ##### CHECK FOR EXPIRED SESSION #####

if ($username == '102_Session key invalid or no longer valid') {

setcookie('facebook_session_key', '');
setcookie('facebook_uid', '');
header('Location: ' . $_SERVER['PHP_SELF']);
print_r($_COOKIE);
} // End IF



} // End Else



} // ### End doConnect() ###



// ### GET USER INFO FUNCTION ###

function get_userinfo() {

return $this->user;

}


} // End cbx_facebookAPI class


?>
[/code]

I am calling this class object on [url=http://www.collegebookx.com/registerAPI/index.php]http://www.collegebookx.com/registerAPI/index.php[/url]

The code is here for the call to it:

[code]<?php

require_once('cbx_facebookAPI.class.php');

$t = new cbx_facebookAPI();
$t->doConnect();

$user = $t->get_userinfo();

print_r($user);



?>[/code]

If you goto the url posted above, you'll see it takes you to facebook login without my api code nor the next..I'm not that great with classes in php yet, am I initializing/calling them incorrectly?
Link to comment
https://forums.phpfreaks.com/topic/34069-facebook-api-help/
Share on other sites

Well, on line 70 you're telling it to redirect to the login page for facebook in the function do_connect. Then your calling it in "$t->doConnect();"
[code]// ##### CHECK FOR USER LOGGED IN #####

if (empty($_COOKIE['facebook_session_key'])) {

// ##### REQUIRE LOGIN #####

header('Location: http://api.facebook.com/login.php?api_key=' . $this->config['api_key'] . '&next=' . $this->config['next']);
} // End IF[/code]

I could be wrong, but I think that's where you're going wrong. I'm no expert in classes though.
Link to comment
https://forums.phpfreaks.com/topic/34069-facebook-api-help/#findComment-160348
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.