Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
157 views

PHP FB API

1. The Facebook PHP SDK provides access to the Facebook Platform through a Facebook class. 2. The Facebook class initializes a Facebook Application, sets application IDs and secrets, and allows invoking the Graph API and making OAuth requests to interact with the Facebook platform. 3. The class handles sessions, cookies, and making HTTP requests to the Facebook APIs and services.

Uploaded by

shambalic
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views

PHP FB API

1. The Facebook PHP SDK provides access to the Facebook Platform through a Facebook class. 2. The Facebook class initializes a Facebook Application, sets application IDs and secrets, and allows invoking the Graph API and making OAuth requests to interact with the Facebook platform. 3. The class handles sessions, cookies, and making HTTP requests to the Facebook APIs and services.

Uploaded by

shambalic
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

FACEBOOK PHP SDK class Facebook

Provides access to the Facebook Platform.

Version 2.0.3 ‐ 11‐5‐2010
http://github.com/facebook/php‐sdk/ public static $CURL_OPTS public function __construct($config) protected function _restserver($params)
// Array ‐ Default options for curl.
Default options for curl. // Initialize a Facebook Application.
pp // Invoke the old restserver.php endpoint.
p p p

public static $DOMAIN_MAP public function setAppId($appId) protected function _graph($path, 


// Array ‐ Maps aliases to Facebook domains. // Set the Application ID. $method='GET', $params=array())
class FacebookApiException public function getAppId()
// Invoke the Graph API.
protected static $DROP_QUERY_PARAMS // Get the API Key.
Thrown when an API call returns an exception. // Array ‐ List of query parameters that get automatically dropped  protected function _oauthRequest($url, 
// when rebuilding the current URL.
public function setApiSecret($apiSecret)
$params)
// Make a OAuth Request
// Set the API Secret.
t t d $appId;
protected 
// The Application ID. protected function makeRequest($url, $params, 
protected $result; public function getApiSecret()
//  The result from the API server that represents the exception
// Get the API Secret. $ch=null)
//  information.
protected $apiSecret; // Makes an HTTP request. This method can be overriden by 
// The Application API Secret. public function  // subclasses if developers want to do fancier things or use 
// something other than curl to make the request.
setCookieSupport($cookieSupport)
public function __construct($result) protected $session; // Set the Cookie Support status.
// Make a new API Exception with the given result. // The active user session, if one is available.
protected function getSessionCookieName() 
// The name of the Cookie that contains the session.
public function useCookieSupport()
public function getResult()
l () protected $sessionLoaded
$ i L d d = false;
f l // Get the Cookie Support status.
protected function 
// Return the associated result object returned by the API server. // Indicates that we already loaded the session as best as we could.
public function setBaseDomain($domain)
setCookieFromSession($session=null)
// Set a JS Cookie based on the _passed in_ session. It does not use 
public function getType() protected $cookieSupport = false; // Set the base domain for the Cookie.
// the currently stored session ‐‐ you need to explicitly pass it in.
// Returns the associated type for the error. This will default to // Indicates if Cookie support should be enabled.
// 'Exception' when a type is not available. public function getBaseDomain() protected function 
// Get the base domain for the Cookie.
protected $baseDomain = ''; validateSessionObject($session) 
// Base domain for the Cookie. // Validates a session_version=3 style session object.
public function __toString() public function setSession($session=null, , 
// To make debugging easier
// To make debugging easier.
$ i
$write_cookie=true)
ki ) protected function getApiUrl($method)
// Set the Session. // Build the URL for api given parameters.

public function getSession() protected function getUrl($name, $path='', 
// Get the session object. This will automatically look for a signed 
example.php // session sent via the Cookie or Query Parameters if needed. $params=array()) 
<?php <!doctype html> appId : '<?php echo $facebook‐>getAppId(); ?>', button></fb:login‐button> // Build the URL for given domain alias, path and parameters.
require '../src/facebook.php'; <html  status : true, // check login status </div>
xmlns:fb="http://www.facebook.com/2008/fbml"> cookie : true, // enable cookies to allow the server to  <div> public function getUser()
// Create our Application instance.
$facebook = new Facebook(array(
<head>
<title>php‐sdk</title>
access the session
xfbml : true // parse XFBML
Without using JavaScript &amp; XFBML:
<a href="<?php echo $loginUrl; ?>"> // Get the UID from the session. protected function getCurrentUrl()
'appId'
appId  => '254752073152',
254752073152 , }); <img
img // Returns the Current URL, stripping it of known FB parameters that 
// Returns the Current URL, stripping it of known FB parameters that
'secret' => '904270b68a2cc3d54485323652da4d14', <style> src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/
// should not persist.
'cookie' => true,
));
body {
font‐family: 'Lucida Grande', Verdana, Arial, sans‐
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
4li2k73z.gif">
</a>
public function getLoginUrl($params=array())
serif; window.location.reload(); </div> // Get a Login URL for use with redirects. By default, full page 
$me = null; } }); <?php endif ?> protected static function 
// Session based API call. h1 a { }; <h3>Session</h3>
// redirect is assumed. If you are using the generated URL with a 
if ($session) { text‐decoration: none; <?php if ($me): ?> // window.open() call in JavaScript, you can pass in display=popup as  generateSignature($params, $secret)
try { color: #3b5998; (function() { <pre><?php print_r($session); ?></pre>
$uid = $facebook‐>getUser(); } var e = document.createElement('script');
// part of the $params. // Generate a signature for the given params and secret.
$me = $facebook‐>api('/me'); h1 a:hover { e.src = document.location.protocol +  <h3>You</h3>
} catch (FacebookApiException $e) { text‐decoration: underline; '//connect.facebook.net/en_US/all.js'; <img src="https://graph.facebook.com/<?php echo 
error_log($e); } e.async = true; $uid; ?>/picture"> public function getLogoutUrl($params=array())
} </style> document.getElementById('fb‐root').appendChild(e); <?php echo $me['name']; ?>
} }()); // Get a Logout URL suitable for use with redirects.
</head> </script> <h3>Your User Object</h3>
// login or logout url
// g g will be needed depending on 
p g <body> y <pre><?php
p p pp print_r($me); ?></pre>
($ ); /p
current user state. <h1><a href="example.php">php‐sdk</a></h1> <?php else: ?> public function 
bl f
if ($me) {
$logoutUrl = $facebook‐>getLogoutUrl();
<!‐‐
We use the JS SDK to provide a richer user  <?php if ($me): ?>
<strong><em>You are not 
Connected.</em></strong> getLoginStatusUrl($params=array()) Cheat Sheet available at
} else { experience. For more info, <a href="<?php echo $logoutUrl; ?>"> <?php endif ?>

}
$loginUrl = $facebook‐>getLoginUrl(); look here: http://github.com/facebook/connect‐js
‐‐>
<img
src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/ <h3>Naitik</h3>
// Get a login status URL to fetch the status from facebook. www.princessdesign.net
cxrz4k7j.gif"> <img
// This call will always work since we are fetching 
public data.
<div id="fb‐root"></div>
<script>
</a>
<?php else: ?>
src="https://graph.facebook.com/naitik/picture">
<?php echo $naitik['name']; ?>
public function api(/* polymorphic */)
$naitik = $facebook‐>api('/naitik'); window.fbAsyncInit = function() { <div> </body> // Make an API call.
?> FB.init({ Using JavaScript &amp; XFBML: <fb:login‐ </html>

You might also like