Title: Facebook Application Development - Error - FacebookAPI.CreateSession() - FacebookAPI.ErrorCheck() - Invalid Parameter Fix Author: Greg Dubinovskiy Email: [email protected] Environment: c# .NET Keywords: Facebook Application Development - Error - FacebookAPI.CreateSession() - FacebookAPI.ErrorCheck() - Invalid Parameter Fix Level: Intermediate Description: Facebook Application Development - Error - FacebookAPI.CreateSession() - FacebookAPI.ErrorCheck() - Invalid Parameter Fix Section Miscellaneous SubSection General
After my greatest Facebook application was sort-of developed, it was time for testing...
Ha-ha! What do I know - it didn't work! Messed with various settings, still wouldn't work! Drove me bananas...
canvas
parameter that can be passed when redirecting to Facebook login.php.
And after experementing with actual URL in browser address, and manually adding canvas parameter in browser URL address, my Facebook application worked as expected.
internal class BasePageHelper
{
...
...
public static void LoadFBMLPage(FacebookService fbService, bool autoAdd, HttpRequest request, HttpResponse response)
{
string sessionKey = null;
string userId = null;
string inCanvas = request[REQUEST_IN_CANVAS];
fbService.IsDesktopApplication = false;
if (string.IsNullOrEmpty(fbService.SessionKey) || string.IsNullOrEmpty(fbService.UserId))
{
sessionKey = request[REQUEST_SESSION_KEY];
userId = request[REQUEST_USER_ID];
}
else
{
sessionKey = fbService.SessionKey;
userId = fbService.UserId;
}
// 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[QUERY_AUTH_TOKEN];
// We have already established a session on behalf of this user
if (!String.IsNullOrEmpty(sessionKey))
{
fbService.SessionKey = sessionKey;
fbService.UserId = userId;
}
//// This will be executed when facebook login redirects to our page
else if (!String.IsNullOrEmpty(authToken))
{
fbService.CreateSession(authToken);
}
else
{
//response.Redirect(@"http://www.facebook.com/login.php?api_key=" + fbService.ApplicationKey + @"&v=1.0");
//check if canvas!
if ( !string.IsNullOrEmpty(inCanvas) && inCanvas.Equals("1"))
{
response.Write("<fb:redirect url=\"" + FACEBOOK_LOGIN_URL + fbService.ApplicationKey + @"&v=1.0&canvas" + "\"/>");
}
else
{
response.Write("<fb:redirect url=\"" + FACEBOOK_LOGIN_URL + fbService.ApplicationKey + @"&v=1.0" + "\"/>");
}
response.End();
}
if (!fbService.IsAppAdded() && autoAdd)
{
if ((!string.IsNullOrEmpty(inCanvas) && inCanvas.Equals("1")) || (!string.IsNullOrEmpty(request.Url.ToString()) && request.Url.ToString().ToLower().Contains("facebook.com")))
{
response.Write("<fb:redirect url=\"" + FACEBOOK_ADD_URL + fbService.ApplicationKey + @"&v=1.0" + "\"/>");
response.End();
}
else
{
response.Redirect(FACEBOOK_ADD_URL + fbService.ApplicationKey + @"&v=1.0");
}
}
}
}
if ( !string.IsNullOrEmpty(inCanvas) && inCanvas.Equals("1"))
{
response.Write("<fb:redirect url=\"" + FACEBOOK_LOGIN_URL + fbService.ApplicationKey + @"&v=1.0&canvas" + "\"/>");
}
else
{
response.Write("<fb:redirect url=\"" + FACEBOOK_LOGIN_URL + fbService.ApplicationKey + @"&v=1.0" + "\"/>");
}
public partial class _App : CanvasFBMLBasePage
{
...
....
new protected void Page_Load(object sender, EventArgs e)
{
AddCanvasParameterToRequestQueryString();
base.Api = FACEBOOKAPIKEY;
base.Secret = FACEBOOK_SECRET;
base.Page_Load(sender, e);
...
....
}
}