Facebook C# SDK Sample code

南楼画角 提交于 2019-12-19 04:23:32

问题


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/


回答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




回答2:


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/.



来源:https://stackoverflow.com/questions/4596890/facebook-c-sharp-sdk-sample-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!