Computer Beacon high quality .NET libraries in open source

Custom API endpoints

There are literally hundreds of endpoints provided by Facebook. Sometimes Facebook will also update, add or remove some of them. For these reasons, FGT cannot practically cover every Facebook API. However, FGT allows developers to easily extend the library to call other endpoints, including those that did not exist at the time of writing the library.

Calling custom endpoints

GET endpoints that return JsonObject

An object is an entity on Facebook, examples include an Album, User, Photo, Post, Page, Event etc. All objects are represented in JsonObject format. To query such object:

JsonObject jo = ComputerBeacon.Facebook.Api.Get("{objectId}");

GET endpoints that return a list of JsonObjects

Some endpoints are called "connections" of objects, they typically return a list of objects, e.g. photos in an album, posts created by the user, invited users in an event etc.

List<JsonObject> objects = ComputerBeacon.Facebook.Api.GetConnectionObjects("{objectId}", "{connection}", "{access_token}");

GET endpoints that return non-JsonObjects

var request = ComputerBeacon.Facebook.FacebookRequest.CreateGet("{path}");
string response = request.GetResponse();

Parameters in endpoint urls

All methods accept an overload which allows developers to specify the parameters:

var dict = new Dictionary<string, string>();
dict["client_id"] = "{appId}";
...

var request = ComputerBeacon.Facebook.FacebookRequest.CreateGet("{path}", dict);

POST variants

var jo = ComputerBeacon.Facebook.Api.Post("{path}", dict);
var request = ComputerBeacon.Facebook.FacebookRequest.CreatePost("{path}", dict);

Examples

Getting Page Access Tokens

//you must have "manage_pages" permission to call the "accounts" endpoint
var
pages = ComputerBeacon.Facebook.Api.GetConnectionObjects("me", "accounts", "{access_token}");
foreach (var jo in pages) {
    var name = jo["name"].ToString();
    var id = jo["id"].ToString();
    var pageAccessToken = jo["access_token"].ToString();
}

Extending AccessTokens

var dict = new Dictionary<string, string>();
dict["grant_type"] = "fb_exchange_token";
dict["client_id"] = "{appId}";
dict["client_secret"] = "{appSecret}";
dict["fb_exchange_token"] = "{accessToken}";

var request = ComputerBeacon.Facebook.FacebookRequest.CreateGet("/oauth/access_token", dict);
var response = request.GetResponse();
var newToken = response.Split('&')[0].Split('=')[1];