Upload
ciklum
View
2.091
Download
3
Embed Size (px)
DESCRIPTION
This presentation was shared by Irina Vedkal during Ciklum PHP Saturday (18/02/2012) in Odessa.
Citation preview
Facebook authorization API
Irina VedkalDeveloper
Berlingske Media IT
Agenda
1. Intoduction;2. Facebook sdk:- front-end implementation;- back-end implementation;- methods to use;- issues and fixes;- facebook graph;
Introduction
Facebook allow: • Social Plugins• Authentication• Analytics
Front-end implementation<html> <head><title>My Facebook Login Page</title></head> <body> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({ appId: 'YOUR_APP_ID', status: true, cookie: true, xfbml: true, oauth: true, }); }; (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script> <div class="fb-login-button">Login with Facebook</div> </body> </html>
View on site
Back-end implementation
require_once("sdk/facebook.php"); $config = array(); $config[‘appId’] = 'YOUR_APP_ID'; $config[‘secret’] = 'YOUR_APP_SECRET'; $facebook = new Facebook($config); Methods:• Facebook::getUser(), • Facebook::getLoginUrl(),• Facebook::getLogoutUrl()
Get login url public function getLoginUrl($params=array()) { $currentUrl = $this->getCurrentUrl();
return $this->getUrl('www', 'login.php', array_merge(array( 'api_key' => $this->getAppId(), 'cancel_url' => $currentUrl, 'display' => 'page', 'fbconnect' => 1, 'next' => $currentUrl, 'return_session' => 1, 'session_version' => 3, 'v' => '1.0', ), $params) ); }
Not set permissions access
$params = array( 'legacy_return' => 1, 'method' => 'permissions.request', 'scope' => 'email', );
Get user - Facebook graph API
https://graph.facebook.com/ID { "id": "100002655856449", "name": "Irina Vedkal", "first_name": "Irina", "last_name": "Vedkal", "link": "http://www.facebook.com/...56449", "gender": "female", "locale": "en_US" } https://graph.facebook.com/100002655856449
Custom fields
https://graph.facebook.com/100002655856449?fields=id,name,picture
{ "id": "100002655856449", "name": "Irina Vedkal", "picture": "http://profile.ak.....jpg" }
Get additional data
http://graph.facebook.com/100002655856449/picture http://graph.facebook.com/100002655856449/picture?type=large Methods:
• /picture;• /events;• /albums; • /photos;
That was it
Time to ask questions )))