Skip to main content

Posts

Showing posts from January, 2011

Facebook connect using graph api

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); ?>