Logging on to facebook
Still trying to get off the ground, and it's not as easy as I was hoping. Think I've been through all the pages I could find on Google now, and still no luck.
At the moment, I've reduced everything down to something really simple:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="FacebookTest.WebForm1" %>
<%@ Import Namespace="Facebook" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.fac开发者_高级运维ebook.com/2008/fbml">
<head runat="server">
<title></title>
</head>
<body>
<p>
</p>
<% var app = new FacebookApp();
if (app.Session == null)
{%>
<img id="fbLogin" src="login-button.png" />
<%
}%>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId: '<%:FacebookSettings.Current.AppId %>', status: true, cookie: true, xfbml: true });
$('#fbLogin').click(function () {
FB.login(function (response) {
if (response.session) {
//window.location = '<%--:Url.Action("Profile") --%>'
} else {
// user cancelled login
}
});
});
</script>
</body>
</html>
Still, there's nothing going on...Could this be a problem with cookies, as I'm running from localhost? I'm really struggling, and help would really be appreciated! My current code won't even allow me to click on the login button...
Cheers!
The problem is you are running on localhost, but your Facebook app requires you come from a URL that is on the same domain (or a subdomain) of the site configured on your app. So if your facebook app is configured as example.com, you will need to modify your host file and add an entry (a subdomain should work if you checked the Facebook box to allow subdomains) for test.example.com and have it point to 127.0.0.1. Then access http://test.example.com:port/ and try the authentication again.
As an alternative to thekaido's answer, try configuring the app URL in the Facebook app to http://localhost/app_virtual_dir/ and let it fly.
Yes, I know - this thread has way too many "answers", but I'm adding this here in the hope that others might find it, and that it is in fact the solution to my problem. That remains to be seen when I get home...But I found the following lines in the sample config I copied off of, and hopefully that's the solution:
<canvasSettings
canvasPageUrl="http://apps.facebook.com/graphtoolkit/"
authorizeCancelUrl="http://apps.facebook.com/graphtoolkit/home/cancel" />
Thanks to both of you. I'm pretty sure I'm stupid, because I spent most of my night fighting to get VS' built-in server to answer requests from outside localhost. Then, for some odd reason, IIS wouldn't work after installing it and I ended up watching cartoons and pouting.
Anyway, after being fresh and grumpy, I got it working after battling through setting up things to allow me to debug through IIS...
Now, I changed my Page_Load to contain only the following: var authorizer = new CanvasAuthorizer(app); authorizer.Perms = "stream_publish"; authorizer.Authorize(this.Request, this.Response);
From what I understand, that really should be enough since this is supposed to be a native fb app, and not be run by itself. Under the application setup on fb, I set the following: Site URL: http:// localhost/FacebookTest/ Canvas page: http:/ /apps.facebook.com/tiwastest/ Canvas URL: http:// localhost/FacebookTest/ Canvas Type: IFrame IFrame Size: Show scrollbars Sandbox: Disable All enabled under Migrations
I then got it more or less running, but after executing authorizer.Authorize, I'm being sent to http://apps.facebook.com/graphtoolkit/WebForm1.aspx (WebForm1.aspx is in fact the page I'm working on). Any of you got any clue about this? I mean - I'm trying to wrap my head around this, but until I figure out how to at least get on this thing, I'm just banging my head into the wall - instead of working on what I should have (another project I would make money off of)...
Cheers!
精彩评论