Does the FacbookToolkit supports the new Graph API/Auth 2.0?

Jun 15, 2010 at 7:22 AM

Hi, I was wondering if there is a support for the Graph API and the new OAuth 2.0 authentication method on facebook.

As I understood from facebook's blog all canvas applications will have to implement the new OAuth method until June 30th.
There are already some users that cannot access my applications because the old RequireLogin feature doesn't work for them....

Anyone knows if this will effect the current Facebook Toolkit version?



Jun 17, 2010 at 5:32 AM

seems like they r supporting it soon.

its not there in the released downloads. but u will have to download the source code and build it by your self. tats wat im doin rite now.

not sure if its fully or partially implemented thou.

Jun 17, 2010 at 6:38 AM

The problem is that every application that haven't changed their way to authonticate users will eventually stop working on the end of this month so I hope there will be a solution until then... 

Jun 17, 2010 at 4:31 PM

It supports the new auth methods.  I've flipped the auth migration switch and it is working fine.  Line prabirshrestha says you need to build from source.

Jun 18, 2010 at 11:19 PM
patja wrote:

It supports the new auth methods.  I've flipped the auth migration switch and it is working fine.  Line prabirshrestha says you need to build from source.

I tried this, and using the traditional code to connect with the user's account but it doesn't work. ie.

_connectSession = new Facebook.Session.ConnectSession(VirtualStockGame_SF.Properties.Settings.Default.FacebookApiKey,
				_connectSession.UseGraphAuth = true;

// this always returns false. 
if (_connectSession.IsConnected() == true)

Are we supposed to use the old Javascript library or the new one here:

Also, I'm assuming the xd_receiver is not required anymore.

thanks for help so far.

Jun 19, 2010 at 2:10 PM

i actually have shifted over to another library - pretty easy and good to use.

the good thing is it uses facebook open graph oauth 2.0 for authentication.

i am also creating a sample mvc app using it. give me a week or so and i will post the sample online along with the source code to download and a blog post on describing how it is done at

im trying to implement almost all the features of facebook, so that it will be like a reference app rather. hope it will solve the problems.

Jun 21, 2010 at 1:09 PM

this is a sample code to use graph api to get list of facebook events.

graph api seems to work.
var graph = new Graph(new DesktopSession(null, false) { AccessToken = "your_access_token", UseGraphAuth = true });

var jsonResult = graph.Post("me", new Dictionary { { "fields", "events" } });
var events = JsonConvert.DeserializeObject<List<FacebookEvent>>(ToJToken(jsonResult)["events"]["data"].ToString());
it works in web app (tats wat i tested on, even though i use DesktopSession). Im using newtonsoft json library which can be found at
the Post() method returns string, so i convert it to JToken and then use deserializeobject to convert it to list of events.
private static JToken ToJToken(string jsonString)
    using (StringReader reader = new StringReader(jsonString))
        using (JsonTextReader jsonTextReader = new JsonTextReader(reader))
            return JToken.ReadFrom(jsonTextReader);
Jun 22, 2010 at 5:46 AM
Edited Jun 22, 2010 at 12:07 PM
Can you provide a code sample for the authontication method using the graph API?
I heard it's not simple and alot of developers couldn't get it to work.
One more question does the access token replaces the session keys?
Jun 28, 2010 at 3:39 AM

actually i use except that im getting some problems with events. (

anyways this is how i login using This sample is not for facebook-toolkit.

first of all u need to derive from AuthorizationController.

public class AuthorizeController : AuthorizationController

    [UnauthorizedLandingPageFilter("CSharpFacebookSample", ParameterName = "facebookAuthorizeUrl", PromptStyle = AuthorizationPromptStyle.Page,
        RequiredPermissions = ExtendedPermissions.OfflineAccess | ExtendedPermissions.ReadStream | ExtendedPermissions.PublishStream
                | ExtendedPermissions.ReadFriendLists | ExtendedPermissions.ReadRequests | ExtendedPermissions.ReadMailbox | ExtendedPermissions.Sms
                | ExtendedPermissions.CreateEvent | ExtendedPermissions.RsvpEvent | ExtendedPermissions.Email | ExtendedPermissions.AboutMe
                | ExtendedPermissions.Activities | ExtendedPermissions.Birthday | ExtendedPermissions.EducationHistory | ExtendedPermissions.Events
                | ExtendedPermissions.Groups | ExtendedPermissions.Hometown | ExtendedPermissions.Interests | ExtendedPermissions.Likes
                | ExtendedPermissions.Location | ExtendedPermissions.Notes | ExtendedPermissions.OnlinePresence | ExtendedPermissions.PhotoVideoTags
                | ExtendedPermissions.Photos | ExtendedPermissions.Relationships | ExtendedPermissions.ReligionPolitics | ExtendedPermissions.Status
                | ExtendedPermissions.Videos | ExtendedPermissions.Website | ExtendedPermissions.WorkHistory)]
    public ActionResult Link(string facebookAuthorizeUrl)
        ViewData["facebookAuthorizeUrl"] = facebookAuthorizeUrl;
        return View();

 Then in your view have the following link to facebook.

 <a href="<%: ViewData["facebookAuthorizeUrl"]%>">Login to facebook</a> to get started... automatically create the url. when you click on the link you are redirected to facebook login page, with persmissions.

if the user logins and accepts the permissions, HandleSuccess function will be called.

protected override ActionResult HandleSuccess(string applicationName, string accessToken, DateTime expiration)
    var graphAuthenticatedSession = new GraphAuthenticatedSession("CSharpFacebookSample",
                                        expiration);   // we dont care about expiration coz its offline_access, its actullay the max value

    // do what you want to do with the accesstoken here. 
    // save in database for later access.

    return View("Success");

once you get the access token you can use the code to query facebook as i mentioned at Jun 21 at 8:09 PM in this post earlier.

hope this helps and sorry for the later reply been quite busy these days.

any more question please feel free to ask.


Jun 28, 2010 at 3:38 PM

I think it is potentially quite confusing to provide source code samples for a different SDK here.  I think it is great there is another option, but maybe the discussion of how to use the other SDK would be better off in the discussion forum for that Codeplex project

Jun 29, 2010 at 4:43 AM

some one has already done the post on how to get the access token using c# web forms.

you can follow up the article to retrieve the access_code. once you get the access_code use facebook toolkit to do graph api calls.

Jul 17, 2010 at 2:51 AM

even i had been creating a Facebook C# SDK. its based on the official android SDK based written in Java.

Some cool features such as IFacebookMembershipProvider is also present. (Sample MySqlFacebookMembershipProvider can be found at

Plans for Silverlight and Windows Phone 7 comming soon along with easy ActionFilters and Controllers for MVC.

Jul 17, 2010 at 9:01 PM
apocolpse wrote:

Announcing the Facebook C# SDK :



Have you checked it out? There is no "there" there. The core code, including extensive comments, is less than 300 lines. And it completely ignores how to generate an auth token. I guess it is an alpha...but it looks like it took all of an hour or so to put together.
Jul 29, 2010 at 1:46 PM

Check out the facebook graph toolkit on codeplex. We started from the ground up to support the new facebook apis. We modeled this sdk off the official PHP SDK so it is very easy to read Facebook's documentation and translate it to C#. Here is an example of how to retrieve some user information:

FacebookApp app = new FacebookApp(); // Config settings stored in web.config or app.config


FacebookApp app = new FacebookApp(new FacebookSettings {
  // Your settings...

dynamic result = app.Api("/me/likes?fields=name,id");
foreach (var like in {
    string name =;
    string id =;

Note, that we don't need to do anything with the authentication. As long as the user is connected, this api will read the cookie for you and automatically include the access_token with the call. If you wanted to do the same thing offline you could also use this constructor: 

FacebookApp app = new FacebookApp("my_access_token_with_offline_access");

Jul 29, 2010 at 2:58 PM

Hi, great to c another Facebook sdk.

my facebook sdk also contains some additional features similar to urs.

var fb = new Facebook("access_token");

var jsonString=fb.Get("/me");

or u can use the generic version

var user = fb.Get<User>("/me");

to get profile picture you need to type

var profileUrl = fb.Get("/me/picture");

but this wuold land up in refering to the facebook api and documentation website. instead there are faecbook extensions to ease the development.

so no you could type

var profileUrl = fb.GetMyProfilePictureUrl();

FacebookSharp also easily allows to integerate between the membership provider using IFacebookMembershipProvider. Incase you are using MVC I have even provided [FacebookAuthorize] attribute.

There are samples for getting access token and acess faceook api for winforms, website and mvc.

you can read about it in my blog or at

 it works in .net client profiles too. :)

Aug 4, 2010 at 10:57 PM

The "which one should I use?" question comes up a lot. As several posters mentioned, the FDT supports the graph API, but you have to build it from the latest source. A reminder that this library is largely a labor of love for the developers involved and definitely not their full-time job. I know all of the people that work on it would love to spend more time on it. Our "other jobs" get in the way!

A little background for people new to the forum. When we originally designed the FDT, we decided on a style/design that a majority of .NET developers are familiar with: drop a control on a WinForm or ASP.NET page and set some properties. Press F5, and the app will automatically bring up a login dialog box when you run it. We included strongly-typed entities. We support SL, WPF, ASP.NET, ASP.NET MVC, Compact Famework (probably deprecated now) and WinForms. We tried to make the code/methods looks like other .NET applications as to serve as a sort of sample app for people new to .NET development. As a result of our decisions, when Facebook changes the API, we have to make changes, too.

Some of the other .NET Facebook APIs are closer to what you use in python or the iPhone. The C# SDK (the one on github and the one I'm most familiar with) implements a simple json parser, wraps http requests into a single line call and an API object to hold/pass your auth token. When Facebook adds a new method, the C# SDK supports it because you are just calling api.Get(“/newmethod”). If we went this route, we’d avoid a lot of complaints when something breaks or when we lag behind changes! In the FDT, we would create a new api.GetNewMethod() and construct a strongly-type object to deserialize into. There's less code in the C# SDK so people don't say “I don’t understand how to use this. I need a sample"...unless they're used to/prefer the "drag, drop, set properties, F5" style.

I'm not suggesting any of the libraries are wrong and I'm only summarizing the C# SDK's features (e.g., it includes extension methods that are similar to the FDT's strongly-typed calls...and come with caveats similar to the FDT); they're just different. They have different goals, different target users, and are solving different problems.

Hope this helps.