Friday, October 4, 2013

How to use Facebook API in your PHP and ASP.NET

Go to http://developers.facebook.com/apps

Setup the necessary information by Clicking on create new app. Get the App Id and App Secret from the site.

Go to  https://developers.facebook.com/docs/reference/php/  Install SDK and use it in your code.

Sample Example:

<?php

$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';

$secret  = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyy';

include_once './.../facebook.php';

$facebook = new Facebook($api_key, $secret);

$user_profile = $facebook->api('/me');

$friendsinfo = $facebook-> api_client->friends_get();

?>


More information and examples are given below:

https://github.com/facebook/facebook-php-sdk


ASP.NET:

string appId = "---------------";
string appSecret = "--------------------";
string pageId = " ------------------- ";

var fbclient = new FacebookClient();

dynamic result = client.Get("oauth/access_token", new
{
    client_id = appId,
    client_secret = appDecret,
    grant_type = "client_credentials"
});

fbclient.AccessToken = result .access_token;

dynamic parameters = new ExpandoObject();
parameters.title = "title";
parameters.message = "message";


var result = fbclient.Post(pageId + "/feed", parameters);

No comments:

Post a Comment