Hi all - this might sound silly but I figured when trying to make an FB app I'd avoid the SDK so I'm not reliant on it .... yeah so anyway.
I've finally got the basics of login and accessing the logged in person's name & picture done - but it's taking so long to do this and I'm sure (even without the SDK) there's a far superior way people have worked out?
Currently my index.php looks like this
and page2.php looks like this
_________________________________
Leozack
I've finally got the basics of login and accessing the logged in person's name & picture done - but it's taking so long to do this and I'm sure (even without the SDK) there's a far superior way people have worked out?
Currently my index.php looks like this
PHP:
// CHECK SESSIONS ENABLED
session_start();
$_SESSION['test'] = "testing";
if($_SESSION['test'] != "testing") {
exit;
}
// CHECK FB/APP LOGIN
header('Location: '."[URL unfurl="true"]https://www.facebook.com/dialog/oauth?client_id=<appid>&redirect_uri=http://www.website.com/page2.php");[/URL]
die();
and page2.php looks like this
PHP:
// CHECK SESSIONS ENABLED
session_start();
$_SESSION['test'] = "testing";
if($_SESSION['test'] != "testing") {
exit;
}
// CHECK FOR DIRECT PAGE LINK
if (!$_GET) {
header('Location: '."[URL unfurl="true"]https://www.facebook.com/dialog/oauth?client_id=<appid>&redirect_uri=http://www.website.com/page2.php");[/URL]
die();
}
// CHECK FOR DENIED LOGON
if (($_GET['error']=="access_denied") and ($_GET['error_code']=="200") and ($_GET['error_description']=="Permissions error") and ($_GET['error_reason']=="user_denied")) {
// "Facebook login is required to use this app";
exit;
}
// GET TOKEN FROM CODE
if ($_GET['code']) {
$response = file_get_contents("[URL unfurl="true"]https://graph.facebook.com/oauth/access_token?client_id=<appid>&redirect_uri=http://www.website.com/page2.php&client_secret=<secret>&code=".$_GET[/URL]['code']);
parse_str($response, $response); // Turn $response string of URL style key/value pairs into array called $response
// TEST TOKEN IS VALID
if ($response) {
$acctok = $response['access_token'];
$inspect = file_get_contents("[URL unfurl="true"]https://graph.facebook.com/debug_token?input_token=".$acctok."&access_token=<appid>|<secret>");[/URL]
$inspect = json_decode($inspect, true);
// CHECK TOKEN CONTENTS ARE VALID
if (($inspect['data']['app_id'] == "<appid>") and ($inspect['data']['is_valid'] == "1") and ($inspect['data']['expires_at'] > time())) {
$uid = $inspect['data']['user_id'];
$uname = file_get_contents('[URL unfurl="true"]https://graph.facebook.com/'.$uid.'?fields=name&access_token='.$acctok);[/URL]
$uname = json_decode($uname, true);
$uname = $uname['name'];
//header('Location '."[URL unfurl="true"]https://graph.facebook.com/".$uid."/picture?type=normal");[/URL]
echo "Welcome ".$uname."<br /><img src='[URL unfurl="true"]https://graph.facebook.com/".$uid."/picture?type=normal'[/URL] />";
} else {
// "Session invalid or timed out - please try logging in again";
exit;
}
}
}
exit;
_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);