user971741
user971741

Reputation:

Alternatives of file_get_contents to retrieve information from graph api

I am developing my first facebook which has now being completed, in my app ive used file_get_contents function to retrieve content from graph api:

$userName =  json_decode(file_get_contents('http://graph.facebook.com/' . $userId)) -> name;

But problem is that the host that I am now using doesn’t allow the use of file_get_contents function.

Kindly help with this.

Thankyou.

Upvotes: 0

Views: 334

Answers (1)

Tebe Tensing
Tebe Tensing

Reputation: 1286

The best solution is to use Facebook PHP SDK.

The code will be similar to:

$app_id     = "Your App ID/API Key goes here";
$app_secret = "Your App secret goes here";
$site_url       = "Your Site URL goes here";

include_once "src/facebook.php";

$facebook = new Facebook(array(
    'appId'     => $app_id,
    'secret'    => $app_secret,
    ));

$user = $facebook->getUser();

if($user){
    try{
        $user_profile = $facebook->api('/me');
    }catch(FacebookApiException $e){
        $user = NULL;
    }
}

if($user){
    $logoutUrl = $facebook->getLogoutUrl();
}else{
    $loginUrl = $facebook->getLoginUrl(array(
        'scope'     => 'read_stream publish_stream email',
        'redirect_uri'  => $site_url,
        ));
}

You can find a detailed tutorial at http://25labs.com/tutorial-integrate-facebook-connect-to-your-website-using-php-sdk-v-3-x-x-which-uses-graph-api/

Upvotes: 2

Related Questions