2

I am using Facebook C# SDk 4.1.1 to develop an application. Is there anyone has a complete sample code for asp.net forms including web config settings? I am really tired making the sample code to work. I believe I am using the correct settings in both facebook app registration and web.Config file

The issue is: When I run my test project from Visual studio it is taking to facebook log in page. After I log in, the app is requesting to authorize it. Once I click on allow button, the brwoser is redirecting to a very long url that has several parameters. But the response is server error.

Can any one explain me what to do once the user clicks on Allow button? I can really appreciate if you can provide me step by step procedure. Thanks

Facebook App Registration Settings

App ID XXXXXXXXXXXXX

API Key xxxxxxxxxxxxxxxxxxxxxxx

App Secret xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Canvas Page apps.facebook.com/smartbuttonthree/

Canvas URL preview.smartbutton.com/dev/

Canvas FBML/iframe iframe

Note: In this post I removed 'http://' for Canvas Page and Canvas URL as I couldn't post more than 1 hyperlink.

Web.COnfig file

    <configuration>
  <configSections>
    <section type="Facebook.FacebookConfigurationSection, Facebook" name="facebookSettings"/>
    <section name="canvasSettings" type="Facebook.Web.CanvasConfigurationSettings, Facebook.Web" />
  </configSections>
  <facebookSettings appId="xxxxxxxx"  appSecret="xxxxxxx"  cookieSupport="true" />
  <canvasSettings 
    canvasPageUrl="http://apps.facebook.com/smartbuttonthree/"  
    canvasUrl="https://preview.smartbutton.com/dev/" 
    authorizeCancelUrl="http://www.facebook.com"/>
  <system.web>
    <httpHandlers>
      <add verb="*" path="facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
    </httpHandlers>
    <compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
    <sessionState mode="Off" />
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <defaultDocument>
      <files>
        <clear />
        <add value="Default.aspx" />
      </files>
    </defaultDocument>
    <handlers>
      <add name="facebookredirect.axd" path="facebookredirect.axd"  verb="*" 
          type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
    </handlers>
  </system.webServer>
</configuration>

Default.aspx.vb

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load   

    fbApp = New FacebookApp()
    authorizer = New CanvasAuthorizer(fbApp)
    authorizer.Perms = requiredAppPermissions

    If (authorizer.Authorize()) Then
      showFacebookContent()
    End If


  End Sub
  Private Sub showFacebookContent()
    Dim myInfo = fbApp.Get("me")
    lblName.Text = "Welcome " & myInfo.name
  End Sub

Update: The app works if I browse to the app (apps.facebook.com/smartbuttonthree) before I log in to facebook account.

App does not work if I log in to facebook first and then browse to apps.facebook.com/smartbuttonthree/

MNVR
  • 865
  • 4
  • 16
  • 30

2 Answers2

1

I found a good starter site here. It is a sample website in C# . You need to use your own API key and secret key to run this app.

Facebook C# Sdk Sample website

Balaji Birajdar
  • 2,394
  • 1
  • 23
  • 29
0

Looks like you got this figured out but if you're still looking for a complete sample, check out my open source ASP.NET 4.0 Facebook Canvas app built with the Facebook C# SDK at http://code.google.com/p/facebooksteamachievements/.

jrummell
  • 42,637
  • 17
  • 112
  • 171
  • That looks great. I linked to your project from the Facebook C# SDK documentation wiki. http://facebooksdk.codeplex.com/documentation – Nate Totten Jan 11 '11 at 00:45
  • This code was throwing 400 bad request error because my redirect URL contains localhost. When I used my prod url, it worked and redirected to facebook login page. – Nps Nov 13 '11 at 16:41
  • sorry, I couldn't even get the solution to open. – Don Rolling Apr 07 '14 at 16:59
  • @jrummell, sorry I don't remember now. I just noticed your comment. Sorry about that. – Don Rolling Dec 17 '14 at 16:06