Working around FacebookSdk.net Permissions BUG FacebookAuthorize attribute

14 בJune 2014

tags: , , ,
4 comments

“Over the past several months Facebook made changes to their application development APIs that were incompatible with the MVC Facebook support.” says N. Taylor Mullen, a developer for the facebooksdk.net team in his latest blog post

So it seems the latest sdk version (6.6.0.0) is incompatible with the current Facebook API hence some features won’t work.

One basic feature mentioned in the tutorial for using the SDK is the FacebookAuthorize attribute which allows asking permissions for the Facebook app.

Could not convert string to integer: installed. Path ‘data[0].permission’, line 1, position 34.

It seems people are aware of the problem but still haven’t came up with a solution. I deiced to share my thoughts of how to handle the issue hoping to save others from this block.

Worth mentioning it has been suggested to use a beta version of the SDK taken from the dev team nightly build but [1] It’s a multi-step process which is not fit for a simple user that just wants to write his first Facebook app (no too complicated tough – it did worked for me..) [2] it is not a good idea to use the beta version in a production app.

The work around

  1. [FacebookAuthorize]
  2.     publicclassHomeController : Controller
  3.     {
  4.         publicasyncTask<ActionResult> Index(FacebookContext context)
  5.         {
  6.             var fb =newFacebookClient();
  7.             var loginUrl = fb.GetLoginUrl(new
  8.             {
  9.                 client_id =GlobalFacebookConfiguration.Configuration.AppId,
  10.                 redirect_uri =“https://localhost:44300/Home/Main”,
  11.                 response_type =“code”,
  12.                 scope =“email,user_likes,publish_stream,publish_actions”// Add other permissions as needed
  13.             });
  14.             Response.Redirect(loginUrl.AbsoluteUri);

Permissions:

Use the following code snippet to request specific permissions (such as user’s email, friends, publish_stream etc) by mentioning them on the scope variable.

Redirect:

redirect_uri is the uri where the app should go to after the user has agreed to the app permission. In my case I have a “Main” view which is returned by the home controller.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

4 comments

  1. Alex Choroshin16 בJune 2014 ב 1:55 am

    Great, thanks for the workaround.

    Reply
  2. Barış20 בJune 2014 ב 8:16 pm

    Refused to display ‘https://www.facebook.com/dialog/oauth?client_id=1464046513830494&redirect_u…onse_type=code&scope=email%2Cuser_likes%2Cpublish_stream%2Cpublish_actions’ in a frame because it set ‘X-Frame-Options’ to ‘DENY’.
    I get an error like this. How can I solve. Thank you.

    Reply
  3. Tom11 בJuly 2014 ב 1:11 am

    Michael,

    I have been struggling for days now getting additional permissions (email, home_town, etc.) using the updated “Microsoft.AspNet.Facebook”, and the information that you have provided as well as information on “https://aspnetwebstack.codeplex.com/workitem/1935”.

    Would it be possible for you to post a working example (VS2013 Project) that shows your “workaround” in action??

    Reply
  4. ashes2219 בSeptember 2014 ב 3:13 pm

    I would like to update your provided solution …
    my new HomeController will be as follows

    [FacebookAuthorize]
    public async Task Index(FacebookContext context)
    {
    if (ModelState.IsValid)
    {
    var fb =new FacebookClient();
    var loginUrl = fb.GetLoginUrl(new
    {
    client_id =GlobalFacebookConfiguration.Configuration.AppId,
    redirect_uri = “https://localhost:44300/”,
    response_type = “code”,
    scope = “email,user_photos,user_likes,publish_stream,publish_actions”// Add other permissions as needed
    });
    // Response.Redirect(loginUrl.AbsoluteUri);
    var user = await context.Client.GetCurrentUserAsync();
    return View(user);
    }

    return View(“Error”);
    }

    My AppUser.cs class in Models Folder

    [FacebookFieldModifier(“limit(4)”)] // This sets the size of the friend list to 8, remove it to get all friends.
    public FacebookGroupConnection Friends { get; set; }

    [FacebookFieldModifier(“limit(4)”)] // This sets the size of the photo list to 16, remove it to get all photos.
    public FacebookGroupConnection Photos { get; set; }

    I have to modify these files as due to redirecturl method , my application was going into an infinite loop

    Reply