samedi 28 mai 2011

How we will use Facebook Graph API

Hello All,

At Facebook's core is the social graph; people and the connections they have to everything they care about. The Graph API presents a simple, consistent view of the Facebook social graph, uniformly representing objects in the graph (e.g.,people, photos, events, and pages) and the connections between them (e.g., friend relationships, shared content, and photo tags).

Every object in the social graph has a unique ID. You can access the properties of an object by requestinghttps://graph.facebook.com/ID. For example, the official page for the Facebook Platform has id 19292868552, so you can fetch the object at https://graph.facebook.com/19292868552:











In PHP, we will request any information we need via the Graph API, and decode the JSON response via the function json_decode().

Cheers,
Mahdi Talhi.


Application Authentication with Facebook PHP SDK

Welcome,

In this first tutorial, I'm gonna explain the application authentication process under Facebook PHP SDK.

1- You have to download the latest Facebook SDK 3.0.0
Github link : https://github.com/facebook/php-sdk/

2- Now you have to include "facebook.php".

3- To verify that the user is logged-in, you can use getUser() function, if the access token is valid, and user is logged-in, it will return the user ID, else we have to redirect the user to the application install page.

Example :
<?php
require 'facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'APP_ID',
  'secret' => 'APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
// We have a valid access token, so we can retrieve user basic informations "ID, name, sex etc....."
  $me = $facebook->api('/me');
  echo "Hello my name is : {$me['name']}";
} else {
// We have to user getLoginUrl() to generate Application install URL, and redirect user via PHP header function, or Javascript.
  $loginUrl = $facebook->getLoginUrl();
  echo "<script>top.location.href=\"{$loginUrl}\"</script>";
}
 
 
That's All,
Feel free to post any question.
Mahdi Talhi.

Welcome to Facebook API Tutorials Blog

Welcome All,

I started this new blog to explain for many web developers how to use the Facebook API, and little documentation about all errors.

Cheers,
Mahdi Talhi.

Many Ways of Making Money Online

You can learn quite a bit about making money online if you have good information first. Here you’re going to learn what goes into th...