I have an iFrame Facebook application. I am using the Facebook C# SDK, Facebook and Facebook.Web libraries.
When a user first comes to my application I create a FacebookApp object on page_load(). If the app.Session is null I create a CavasAuthorizer(app) then call Authorize().
Two problems:
First, the redirect URL that is generated by calling Authorize causes Facebook to error with a bad "next" parameter. Says the "next" parameter is not owned by the application. It looks like this:
next=http://localhost:4002/facebookredirect.axd/mygame_dev/mygame.aspx
I can edit the code in CanvasURLBuilder to make the next look like this:
next=http://localhost:4002/mygame.aspx
At this point the URL works if I cut and paste into a browser however it brings me to my second issue.
When the code runs the user is presented with a mostly empty page with a mid-sized Facebook image and a link "go to Facebook". When the user clicks on the link it then takes the user to the correct authorization page for my application.
I have a feeling these are two possibly related issues but potentially separate.
Any help here would be greatly appreciated.
-Andy
For the first problem
Make sure the site Url in the app configuration page is set to http://apps.facebook.com/[your_app]/

For the second problem.
When you are not authorized you are redirected to the login url but you can't do it from your iframe since it will redirect the iframe and you will get a Facebook inside facebook.
You should use window.top.location = ... to redirect the parent window.
EDIT
Facebook C# SDK Already does this for you when using the Mvc part of the SDK. Since you are using webforms you should use this code that is the equivalent.
protected void Page_Load(object sender, EventArgs e)
{
var fb = new FacebookApp();
var auth = new CanvasAuthorizer(fb);
if (!auth.IsAuthorized())
{
var url = auth.GetLoginUrl(new HttpRequestWrapper(Request));
var content = CanvasUrlBuilder.GetCanvasRedirectHtml(url);
Response.ContentType = "text/html";
Response.Write(content);
Response.End();
return;
}
//...Go on if authorized
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With