170 likes | 194 Views
Teppo Räisänen Teppo.raisanen@oamk.fi School of Business and Information Management. Facebook API. FBML and FBJS. API = application programming interface It is a way to utilize Facebook core features and user data. FBML and FBJS. FBML is similar to HTML FBJS is similar to JavaScript
E N D
Teppo Räisänen | Oulu University of Applied Sciences Teppo Räisänen Teppo.raisanen@oamk.fi School of Business and Information Management Facebook API
Teppo Räisänen | Oulu University of Applied Sciences FBML and FBJS • API = application programming interface • It is a way to utilize Facebook core features and user data
Teppo Räisänen | Oulu University of Applied Sciences FBML and FBJS • FBML is similar to HTML • FBJS is similar to JavaScript • API-calls are close to PHP-function calls • The reason for that is that we use Facebook’s PHP-API
Teppo Räisänen | Oulu University of Applied Sciences API -calls <?php require_once ”facebook.php”; $apikey = ”asdflgasdflkhasdfgasdlfg”; $secret = ”asdf8970adsf70as78asdf”; $facebook= new Facebook($apikey, $secret); $user=$facebook->require_login(); print $user; ?>
Teppo Räisänen | Oulu University of Applied Sciences API • API-calls allow developers to utilize Facebook core features and data • “get the user’s friends” • “get/set user’s status” • “Publish data to user’s profile” • “Make a SQL-query to Facebook database” • You don’t have to use them • They do allow more complicated applications!
Teppo Räisänen | Oulu University of Applied Sciences API • http://developers.facebook.com/docs/ • Facebook is constantly developing the API • The examples here use REST API • http://developers.facebook.com/docs/reference/rest/ • Graph API is the new version • http://developers.facebook.com/docs/reference/api/
Teppo Räisänen | Oulu University of Applied Sciences REST API • Administrative methods • Handles application and user data • Examples • admin.banUsers • admin.getMetrics • Login/Auth methods • Logins and session handling • Usually you don’t need to use this • Example • auth.expireSession
Teppo Räisänen | Oulu University of Applied Sciences REST API • Data retrieval methods • Data handling • Most often used part of the API • Examples • friends.get, status.get • users.getInfo • Publishing methods • Publish data on profile/home page • Important for viral growth! • Examples • stream.publish • status.set
Teppo Räisänen | Oulu University of Applied Sciences REST API • Facebook Connect methods • For using Facebook Connect • Mobile methods • Sending SMS • Dashboard API methods • Handles dashboard calls • dashboard.addNews • Events API methods • Handles Facebookin events • Events.create • Custom Tags API methods • Handles custom made tag calls
Teppo Räisänen | Oulu University of Applied Sciences API-calls in PHP • You utilize the API-calls in PHP like this • Create a facebook-instance from Facebook class • $facebook->api_client->FUNCTION_CALL();
Teppo Räisänen | Oulu University of Applied Sciences API-calls from PHP $facebook = new Facebook($apikey, $secret); $facebook->api_client-> users_getInfo($user, “first_name”); • Note, that users.getInfo is: • users_getInfo • Usually API-calls return an array
Teppo Räisänen | Oulu University of Applied Sciences API-calls from PHP $user_details = $facebook->api_client-> users_getInfo($user, 'last_name, first_name’); $firstname=$user_details[0]['first_name']; $lastname=$user_details[0]['last_name']; print “Your name is $firstname $lastname”;
Teppo Räisänen | Oulu University of Applied Sciences API-call examples Get all $user’s friends: $friends= $facebook->api_client->friends_get($user); Get all $user’s photos: $photos = $facebook->api_client->photos_get($user,'',''); Set status: $facebook->api_client->users_setStatus("facebook coding");
Teppo Räisänen | Oulu University of Applied Sciences API-calls in PHP • Some API-calls require special permissions • status update • Retrieving data does not usually need permission • http://developers.facebook.com/docs/reference/fbml/prompt-permission/ • publish_stream, read_stream • email, read_mailbox • offline_access • create_event, rsvp_event • sms • status_update • photo_upload, video_upload • create_note • share_item
Teppo Räisänen | Oulu University of Applied Sciences API-calls in PHP You can chech the permission with users.hasAppPermission $facebook->api_client->users_hasAppPermission('status_update'); • Returns 1, is there is permission to status update. 0 if not You can ask permission with fb:prompt-permission FBML-tag: <fb:prompt-permission perms='status_update'> Permit the app to update your status? </fb:prompt-permission> You can use many permissions at the same time: <fb:prompt-permission perms=’publish stream, status_update'> Permit the app to publish to stream and update your profile? </fb:prompt-permission>
Teppo Räisänen | Oulu University of Applied Sciences FQL • Facebook Query Language – FQL • http://developers.facebook.com/docs/reference/fql • Allows SQL-querys to Facebook database • $sql = “SELECT name, pic FROM user WHERE uid= 720633037”; • $results = $facebook->api_client->fql_query($sql);
Teppo Räisänen | Oulu University of Applied Sciences Facebook Tools • Facebook has few tools that can be used to test e.g. FBJS • http://developers.facebook.com/tools/