An example of using facebook graph api to authenticate users:
Setup a new application in facebook apps and get the app id and secret.
Now follow the steps:
Remember to give the same url in the below code, as that of the app settings.
<?php
if( !isset($_GET['code'])) { ?>
<a href="https://graph.facebook.com/oauth/authorize?client_id=xxxxxxxx&redirect_uri=http://xxxxxxxxxxxxxxxx/">Connect using Facebook</a>
<?php }
$code = trim($_GET['code']);
if(isset($_GET['code']))
$token = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=xxxxxxxx&redirect_uri=http://xxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxx&code=$code");
$token = explode("=", $token);
if(isset($_GET['code']))
$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$token[1])); print_r($user);
?>
Setup a new application in facebook apps and get the app id and secret.
Now follow the steps:
Remember to give the same url in the below code, as that of the app settings.
<?php
if( !isset($_GET['code'])) { ?>
<a href="https://graph.facebook.com/oauth/authorize?client_id=xxxxxxxx&redirect_uri=http://xxxxxxxxxxxxxxxx/">Connect using Facebook</a>
<?php }
$code = trim($_GET['code']);
if(isset($_GET['code']))
$token = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=xxxxxxxx&redirect_uri=http://xxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxx&code=$code");
$token = explode("=", $token);
if(isset($_GET['code']))
$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$token[1])); print_r($user);
?>
This is really a great post. I will be coming back for sure
ReplyDeleteThanks for reading this...
ReplyDeleteIts realy realy gr8 to see your work. Good job, congrats, keep it up
ReplyDelete