GET Variables wiped during log-on process

Jun 23, 2009 at 4:05 AM

Hi,

I'm new to the Facebook API, but I've stumbled my way through putting together a simple application written in C# using the Facebook Toolkit.

I've got my application doing what I need it to for now, but I've got one issue. I'd like to pass a variable to my application via a GET request. I.e. http://apps.facebook.com/myapplication/default.aspx?variable=value

I've got it all working, except in the situation where the user has not logged into Facebook yet. As soon as the log-in prompt is shown it drops the variable passed to the app.

I can see from my webservers logs that the variable is present at some point when it hits my app, so I was wondering if there is a way to start a session, or store cookie values, before the user is actually logged in.

Is there a better way to acheive this?

A brief outline of the code is found below. The log-in screen is forced during the Page_PreInit by having the this.RequireLogin = true present. If I set this to false, and try to use FBML to redirect to the login.php manually, with next= set, I get all sorts of errors, where it redirects back to my page rather than the facebook site.

 

<%

// START C#

using System;
...
...
using facebook;
using facebook.web;

public partial class _Default : CanvasFBMLBasePage
{
    private string FACEBOOK_API_KEY;
    private string FACEBOOK_SECRET;
    ...
    ...
    facebook.Schema.user me;

    protected void Page_PreInit(object sender, EventArgs e)
    {
        this.RequireLogin = true;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        FACEBOOK_API_KEY = ConfigurationManager.AppSettings["APIKey"];
        FACEBOOK_SECRET = ConfigurationManager.AppSettings["Secret"];
        ...
        ...
        me = this.API.users.getInfo();
        runApp();

     }

     runApp(){
         //do stuff
     }
}


//END C#

%>

Jun 23, 2009 at 6:58 AM

FYI, All. I managed to solve this with the below code smile

<%

// START C#

using System;
...
...
using facebook;
using facebook.web;

public partial class _Default : CanvasFBMLBasePage
{
    private string FACEBOOK_API_KEY;
    private string FACEBOOK_SECRET;
    ...
    ...

    facebook.Schema.user me;

    protected void Page_PreInit(object sender, EventArgs e)
    {
        string myVar = Request.QueryString["myvariable"];

        Response.Write("<fb:if-is-app-user>\n");
        Response.Write("<fb:else>\n");
        Response.Write("        <fb:redirect url=\"http://www.facebook.com/login.php?v=1.0&api_key=" + FACEBOOK_API_KEY + "&next=default.aspx%3Fmyvariable%3D" + HttpUtility.UrlEncode(myvariable) + "&canvas=\"/>\n");
        Response.Write("</fb:else>\n");
        Response.Write("</fb:if-is-app-user>\n");

        this.RequireLogin = true;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        FACEBOOK_API_KEY = ConfigurationManager.AppSettings["APIKey"];
        FACEBOOK_SECRET = ConfigurationManager.AppSettings["Secret"];
        ...
        ...
        me = this.API.users.getInfo();
        runApp();

     }

     runApp(){
         //do stuff
     }
}


//END C#

%>