How to connect to facebook, and debug facebook application using C# SDK

此生再无相见时 提交于 2019-12-20 10:56:07

问题


I'm really struggling trying to find something that actually works for getting the basics up and running. Even the tutorial apps that came with the SDK seems to have to be uploaded in order to work, so there's no easy way to debug and test it locally.

Anyone got a link to a working sample I could work off of?

Cheers!


This is what I currently have in my aspx. There's nothing in the code-behind:

<%@ 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.facebook.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>

回答1:


I am also fighting with this sdk. For local testing you must do the following

  1. In Facebook application settings go to Website tab and change site URL to "http://localhost/"
  2. You also need to set your asp.net development server port to 80 (write click your project and click properties, go to Web tab User Visual Studio Development server specific port). We are doing this because we set our site url to localhost, Facebook dont allow port number in site url.


来源:https://stackoverflow.com/questions/4118994/how-to-connect-to-facebook-and-debug-facebook-application-using-c-sharp-sdk

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