DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Facebook (Graph) API Class Using Javascript And PHP. (Page Example).

10.08.2010
| 4845 views |
  • submit to reddit
        <?php
	// Require the class.
	require_once 'Facebook.php';
	
	// Create a new instance of Facebook with your ApplicationID and SecretKey.
	$Facebook = new Facebook("155715524462317", "73ae58208657e6d9e52d12ad8deff720");
	
	// Get the current status of your Facebook cookie (Will return NULL if not logged in, or authenticated).
	$Cookie = $Facebook->catchCookie();
?>
<!DOCTYPE html>
<!-- DONT FORGET TO INCLUDE FBML! -->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
	<head>
		<title>Facebook Class</title>
	</head>
	<body>
		<?php
			// Check the Cookie status.
			if($Cookie) {
				// If you have been logged in, assign a array containing all basic information to a variable.
				$User = $Facebook->getUserInfo($Cookie);
				
				// Print the variable (As a test, I suppose?).
				print_r($User);
			} else {
				// The user is either logged out of Facebook, not authenticated to your application, or both. Show the login button :).
				echo $Facebook->loginButton();
			}
			
			// This quickly compiles all the Javascript and DIVS needed to run the FacebookAPI (You can do it yourself, but this makes the code look cleaner).
			$Facebook->Compile();		
		?>
	</body>
</html>