'facebook.Components.FacebookService' does not contain a definition for 'UserId'

Nov 6, 2008 at 9:07 AM
Hello there,

I am very new to the whole ASP.NET and Facebook API thing, but have been asked by my boss to play around with this and see what I can achieve for a future project of ours. I am following the Web Application: Authentication Process from the User Guide, but I cannot build the application, I seem to be getting this error:

'facebook.Components.FacebookService' does not contain a definition for 'UserId' and no extension method 'UserId' accepting a first argument of type 'facebook.Components.FacebookService' could be found (are you missing a using directive or an assembly reference?)

Is there something I am doing wrong? There is no difference between my code and the code in the doc file, and cannot find anything on the internet with people have a similar problem. Help would be much appreciated!

Here is my code:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using facebook;
using facebook.web;

public partial class _Default : System.Web.UI.Page
{
    facebook.Components.FacebookService _fbService = new facebook.Components.FacebookService();

    protected void Page_Load(object sender, EventArgs e)
    {
        // ApplicationKey and Secret are acquired when you sign up for
        _fbService.ApplicationKey = "<API>";
        _fbService.Secret = "<SECRET>";

        string sessionKey = Session["Facebook_session_key"] as String;
        string userId = Session["Facebook_userId"] as String;

        // When the user uses the Facebook login page, the redirect back here will will have the auth_token in the query params
        string authToken = Request.QueryString["auth_token"];

        if (!String.IsNullOrEmpty(sessionKey))
        {
            _fbService.SessionKey = sessionKey;
            _fbService.UserId = userId;
        }

        else if (!String.IsNullOrEmpty(authToken))
        {
            _fbService.CreateSession(authToken);
            Session["Facebook_session_key"] = _fbService.SessionKey;
            Session["Facebook_userId"] = _fbService.UserId;
            Session["Facebook_session_expires"] = _fbService.SessionExpires;
        }

        else
        {
            Response.Redirect(@"http://www.Facebook.com/login.php?api_key=" + _fbService.ApplicationKey + @"&v=1.0");
        }

    }
}

(I have removed my API and Secret key for obvious reasons :P)
Developer
Nov 6, 2008 at 1:47 PM
Yes, the documentation was not updated for RC3. You can find the correct code in a similar discussion here: http://www.codeplex.com/FacebookToolkit/WorkItem/View.aspx?WorkItemId=11551

You can get the updated User's Guide from source control on the Source Code tab above, or you can wait and get it with the full release in a few days.
Developer
Nov 6, 2008 at 1:48 PM
Actually, it's probably less than "a few days". Let's just say "soon".
Nov 10, 2008 at 3:18 PM
Edited Nov 10, 2008 at 3:27 PM
I have downloaded the latest build and seems that code still hasn't been updated. And also looking at the thread you posted, those fixes do not work. Here are the errors I am getting:

Error    1    Cannot implicitly convert type 'string' to 'long'

Error    2    'facebook.Components.FacebookService' does not contain a definition for 'userId' and no extension method 'userId' accepting a first argument of type 'facebook.Components.FacebookService' could be found (are you missing a using directive or an assembly reference?)

Error    3    An object reference is required for the non-static field, method, or property 'facebook.Components.FacebookService.friends.get'

Edit:

Did some more playing, and have got it down to 2 errors!

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using facebook;
using facebook.web;
using facebook.Components;

public partial class _Default : System.Web.UI.Page
{
    facebook.Components.FacebookService _fbService = new facebook.Components.FacebookService();

    protected void Page_Load(object sender, EventArgs e)
    {
        // ApplicationKey and Secret are acquired when you sign up for
        _fbService.ApplicationKey = "2faa55513175329c25dd497b8fd03d6f";
        _fbService.Secret = "ec2850c2d31b12bb0a9705dc0a050217";

        string sessionKey = Session["Facebook_session_key"] as String;
        string userId = Session["Facebook_userId"] as String;

        // When the user uses the Facebook login page, the redirect back here // will will have the auth_token in the query params
        string authToken = Request.QueryString["auth_token"];

        // We have already established a session on behalf of this user
        if (!String.IsNullOrEmpty(sessionKey))
        {
            _fbService.SessionKey = sessionKey;
            //_fbService.userId = userId;
            _fbService.uid = userId;
        }
        // This will be executed when Facebook login redirects to our page
        else if (!String.IsNullOrEmpty(authToken))
        {
            _fbService.CreateSession(authToken);
            Session["Facebook_session_key"] = _fbService.SessionKey;
            Session["Facebook_userId"] = _fbService.uid;
            Session["Facebook_session_expires"] = _fbService.SessionExpires;
        }
        // Need to login
        else
        {
            Response.Redirect(@"http://www.Facebook.com/login.php?api_key=" + _fbService.ApplicationKey + @"&v=1.0\");
        }

        if (!IsPostBack)
        {
            // Use the FacebookService Component to populate Friends
            //MyFriendList.Friends = _fbService.GetFriends();
            FriendList1.Friends = FacebookService.friends.GetUserObjects();
        }

    }
}
Errors:
Error    1    Cannot implicitly convert type 'string' to 'long'

Error    2    An object reference is required for the non-static field, method, or property 'facebook.Components.FacebookService.friends.get'
Nov 10, 2008 at 3:31 PM
Haha, Sorry to spam, but I have managed to get rid of Error 2, by changing the get friends line to:

            FriendList1.Friends = _fbService.friends.getUserObjects();

Just the 'convert type 'string' to 'long'' error :S
Developer
Nov 10, 2008 at 6:26 PM
See the newest version of the User's Guide. It's been updated to work with the updated code.