WTH am I doing wrong? Can not get basic FB API calls working.

Feb 7, 2010 at 6:46 PM

Well once again I can't get anything working in this SDK. In the past I have asked for help toget the UID of players and how to propomt user to allow access for my page, while each one was answered I can not implement the answers cause the code does not work. I am trying to create an Iframe application and as such in my .master page I have the following code:

public class BasicInfo:CanvasIFrameMasterPage 
{
    //Set API key and application secret for Facebook
    private const string Key = "MyKey";
    private const string FBSecret = "MyScecret";

    //Create a new instance of the Facebook API to make calls to
    Facebook.Session.IFrameCanvasSession FBSession = new Facebook.Session.IFrameCanvasSession(Key, FBSecret);
    Facebook.Rest.Api api = new Facebook.Rest.Api(FBSession);

    //protected Facebook.Rest.Api api {get { return new Facebook.Rest.Api(new Facebook.Session.IFrameCanvasSession(Key, FBSecret));}}

    
    //Get the Facebook UID of the current player
    protected string m_CurrentUID = api.Users.GetInfo().uid;
}
On the line that has Facebook.Rest.Api api = new Facebook.Rest.Api(FBSession); I am  told FBSession I can not use it with error: 
"A field initializer cannot refernce the non-static field, method or property 'BasicInfo.FBSession'"
If I uncomment the //protected .... line I get the same erro but on the protected string m_CurrentUID = api.Users.GetInfo().uid; line at "api"
So WTH am I doing wrong? I tried reading the documenation but it tells me nothing as most of the information is missing, I tried to look at the samples but they don't open or make no sense ( I have never seen .aspx.designer.cs files)

Feb 8, 2010 at 10:18 PM

No one can help me figure out the right way to a new instance of the API in an IFRAM app? PLEASE

Feb 9, 2010 at 2:00 AM
Edited Feb 9, 2010 at 2:02 AM

I followed the example in this thread:

Version 3.01 still doesn't work for iFrame apps - DEVELOPERS PLEASE HELP

Here is what I have in default.aspx:

using Facebook;
using Facebook.Rest;
using Facebook.Web;

public partial class _Default : CanvasIFrameBasePage
{
    public _Default()
    {
        RequireLogin = true;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        long id = Api.Users.GetLoggedInUser();

        Facebook.Schema.user u = Api.Users.GetInfo(id);

        lblName.Text = "Welcome " + u.first_name + ", your birthday is " + u.birthday;
    }
}

Default.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Label ID="lblName" runat="server" Text=""></asp:Label><br />
</asp:Content>
MasterPage.master:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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">
<head runat="server">
    <title>My Title</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>

<body>
    <form id="form1" runat="server">
    <div id="topContent">
    </div>
    <div id="mainContent" style="height:100%">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    <div id="footerContent">        
    </div>
    </form>
</body>
</html>
MasterPage.master.cs
using Facebook;
using Facebook.Web;

public partial class MasterPage : CanvasIFrameMasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
Web.config:
<appSettings>
    <add key="ApiKey" value="aaaaaaaaa"/>
    <add key="Secret" value="bbbbbbbbb"/>
</appSettings>
<system.net>
    <settings>
    <!--   Without the following attempting to call FaceBookService.CreateSession results in:
The server committed a protocol violation. Section=ResponseStatusLine -->
    <httpWebRequest useUnsafeHeaderParsing="true"/>
    </settings>
</system.net>

This is working for me
Feb 26, 2010 at 9:52 PM
Edited Jun 24, 2010 at 10:17 PM

I'm using 3.01 for an iFrame App, and here's what's working for me, today:

The Master ASPX Page named IFrameMaster.master.aspx

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="IFrameMaster.master.cs" Inherits="IFrameMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head id="Head1" runat="server">
    <title>Welcome!</title>
        <link rel="Stylesheet" type="text/css" href="css/fbstyle.css" />
        <link rel="Stylesheet" type="text/css" media="print" href="css/print.css" />
        <link rel="Stylesheet" type="text/css" media="screen" href="css/screen.css" />        
        <asp:ContentPlaceHolder ID="head" runat="server" />
</head>
<body>
    <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
    <form id="form1" runat="server">
        <asp:ContentPlaceHolder id="body" runat="server" />
        <asp:ContentPlaceHolder id="footer" runat="server" />
        <script type="text/javascript">
        FB_RequireFeatures(["XFBML"], function() {
        FB.Facebook.init("f03zc924a952e192a290af4be3gd09", "channel/xd_receiver.htm");
        });
    </script>
    </form>
</body>
</html>
 
The Master C# Page Behind named IFrameMaster.master.cs
using Facebook;
using Facebook.Schema;
using Facebook.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class IFrameMaster : Facebook.Web.CanvasIFrameMasterPage
{
    public IFrameMaster()
    {
        RequireLogin = true;
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
The Default ASPX Page named Default.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/IFrameMaster.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" EnableSessionState="True" %>
<%@ MasterType VirtualPath="~/IFrameMaster.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
	<asp:Label ID="LabelGreeting" runat="server" Text="Label"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
</asp:Content>

The Default C# Page behind named Default.aspx.cs
using Facebook;
using Facebook.Schema;
using Facebook.Web;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Facebook.Schema.user me = Master.Api.Users.GetInfo(Master.Api.Session.UserId);
            LabelGreeting.Text = "Hi, " + me.first_name + " welcome to my Facebook App...arrrrrg shiver me timbers mate!";	
        }
    }
}
The ApiKey and Secret are in the Web.config file:

<appSettings>
    <add key="ApiKey" value="aaaaaaaaa"/>
    <add key="Secret" value="bbbbbbbbb"/>
</appSettings>
I hope this is useful.
LuoLong
 
Apr 8, 2010 at 7:31 PM

Hi Everyone,

I am a noob when it comes to ASP.NET [I work as winforms developer, however have been tasked by my boss to do a Facebook application to promote our company]. I tried example posted by LuoLong, however I keep on getting following error message:

HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.

For testing purposes I'm using freehosting solution...might this be the case ? how can I get rid of this message ?

Any help would be greatly appreciated.

Regard, Bruno

Jun 7, 2010 at 8:59 PM

Should this be fixed in 3.1 Beta?

Jul 24, 2010 at 4:16 PM
I downloaded the latest patch from the source section of the site and i can get the IFrame sample application to work somewhat (at least it shows the select a color page). You may want to try downloading it: click download on the right hand side: http://facebooktoolkit.codeplex.com/SourceControl/list/changesets Luis PS - If you get the canvas sample app working let me know, I can't.
Jul 27, 2010 at 6:15 PM

check this up....

Going through the following articles, step by step will let you to access facebook api from a vb.net based desktop application.

http://geekdeck.com/how-to-access-facebook-api-from-net/

http://geekdeck.com/vb-net-facebook-get-access-token-for-desktop-application/

http://geekdeck.com/net-get-facebook-user-profile-id-uid/

http://geekdeck.com/net-api-get-facebook-user-status-comments-picture-and-other-details/