Authorization AuthToken problem

Apr 29, 2009 at 8:21 PM
I've been struggling with this Toolkit for a few days now and need some help.

I have implmented the following code to connect/login to FB, but I end up with no session key, and if I try to do soemthing like
user u = fbService.users.getInfo();

then u is null.

What am I doing wrong???


 

public

 

partial class _Default : CanvasFBMLBasePage

 

{

 

private facebook.Components.FacebookService _fbService;

 

public facebook.Components.FacebookService fbService

 

 {

 

get  {

 

 

if (this._fbService == null)

 

 {

     

this._fbService = new FacebookService();

 

 }

 

return this._fbService;

 

 }

 

set   {

 

 

this._fbService = value;

 

 }

}

 

 

protected void Page_PreInit(object sender, EventArgs e)

 {

 

base.RequireLogin = true;

 

 }

 

protected void Page_Load(object sender, EventArgs e)

 

 {

 

string SessionKey;

 

 

string TokenAuthentication;

 

 

long UserId;

 

 UserId = 0;

SessionKey = 

String.Empty;

 

 TokenAuthentication =

String.Empty;

 

 

// Set API key and secret for the FacebookService from web.config

 

 

fbService.ApplicationKey =  ConfigurationManager.AppSettings["APIKey"];

 

 fbService.Secret =

ConfigurationManager.AppSettings["Secret"];

 

 

// Set up the IsDesktopApplication for the FacebookService

 

 

fbService.IsDesktopApplication = false;

 

 SessionKey = (

string)Session["FacebookSessionKey"];

 

 

if (Session["FacebookUserId"] != null)

 

 {

UserId = (

long)Session["FacebookUserId"];

 

 }

 

// When the user uses the Facebook login page, the redirect back here

 

 

// will have the auth_token in the query string

 

 

TokenAuthentication = (string)Request.QueryString["AuthToken"];

 

 

// We have already established a session on behalf of this user

 

 

if (!String.IsNullOrEmpty(SessionKey))

 

 {

fbService.SessionKey = SessionKey;

fbService.uid = UserId;

}

 

// If not, check if we have auth_token in the query params.

 

 

// If we do, it means we just got called from the Facebook login page.

 

else if (!String.IsNullOrEmpty(TokenAuthentication))

{

fbService.CreateSession(TokenAuthentication);

Session[

"FacebookSessionKey"] = fbService.SessionKey;

 

 Session[

"FacebookUserId"] = fbService.uid;

 

 Session[

"FacebookSessionExpires"] = fbService.SessionExpires;

 

 }

 

// If neither, we are not authenticated

 

 

else {

 

 

 Response.Write("<fb:if-is-app-user>");

 

 Response.Write(

"<fb:else>");

 

 Response.Write(

"<fb:redirect url=\"http://www.facebook.com/login.php?api_key=" + fbService.ApplicationKey + "&v=1.0\"/>");

 

 Response.Write(

"</fb:else>");

 

 Response.Write(

"</fb:if-is-app-user>");

 

 }

 

 

try

 

 

{

 

 lblMessage2.Text += fbService.SessionKey ;

 

//user u = fbService.users.getInfo();

 

 

//lblMessage2.Text = (u != null).ToString();

 

 

//IList<user> friends = fbService.friends.getUserObjects();

 

 

//FriendList1.Friends = friends;

 

 

}

 

 

catch (Exception ex)

 

 {

lblMessage2.Text = ex.Message;

}

}

}

 

May 2, 2009 at 1:28 AM
I think the code above is meant for Facebook Connect.

I was able to follow the example from this thread  http://facebooktoolkit.codeplex.com/Thread/View.aspx?ThreadId=53322
and everything is working great now!

-D