简体   繁体   English

使用asp.net使用Facebook c#sdk或javascript sdk在Face Book Wall上发布

[英]Post On Face Book Wall using asp.net using Facebook c# sdk or javascript sdk

我需要使用Facebook c#sdk和mvc或asp.net Web窗体在Facebook墙上发布,欢迎它,这不会有什么不同,并且有Java脚本sdk会很好,或者使用Facebook c#sdk更好

you can use javascript with server side code no need for facebook c# sdk if your case do not need a lot of work and cases : 如果您的案例不需要很多工作和案例,则可以将javascript与服务器端代码一起使用,而无需使用Facebook c#sdk:

you can create a user control like this : 您可以创建这样的用户控件:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FacebookShare.ascx.cs"
Inherits="FacebookApplication.Controls.FacebookShare" %>
<div>
    <div id="fb-root">
    </div>
    <div onclick="return shareWithFacebook();" style="border: 1px solid black;
 background-color: #d3dde5;
        padding: 5pt; width: 175pt; cursor: pointer;">
        <img src='http://www.codeproject.com/images/fb_share.gif' border="0"
 alt="facebook likeus" style="vertical-align: middle;
            padding-right: 5pt;" />
        <strong>Share with Facebook</strong>
    </div>
    <script type="text/javascript">
        window.fbAsyncInit = function () {
            FB.init({ appId: '<%= ApplicationId %>', status: true, cookie: true,
                xfbml: true
            });
        };
        (function () {
            var e = document.createElement('script');
            e.async = true;
            e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
        } ());

        function shareWithFacebook() {
            FB.ui({ method: 'stream.publish',
                message: '<%= Message %>',
                user_message_prompt: '<%= Prompt %>',
                attachment: {
                    name: '<%= Name %>',
                    caption: '<%= Caption %>',
                    description: ('<%= Description %>'),
                    href: '<%= Href %>',
                    media: [{ 'type': 'image', 'src': '<%= Image %>',
   'href': '<%= Href %>'}]
                },
                action_links: [
                { text: '<%= Name %>', href: '<%= Href %>' }
            ]
            },
            function (response) {
                if (response && response.post_id) {
                    // Do some custom action after the user successfully
    // posts this to their wall
                    alert('Thanks for sharing!');
                }
            }
        );
            return false;
        }
    </script>
</div>

the code behind : 后面的代码:

namespace FacebookApplication.Controls
{
    public partial class FacebookShare : System.Web.UI.UserControl
    {
        public string Message { get; set; }
        public string Prompt { get; set; }
        public string Name { get; set; }
        public string Caption { get; set; }
        public string Description { get; set; }
        public string Href { get; set; }
        public string Image { get; set; }
        public string ApplicationId { get; set; }
    }
}

and withing you aspx page : 和你一起aspx页面:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"
 AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="FacebookApplication._Default" %>

<%@ Register src="Controls/FacebookShare.ascx" tagname="FacebookShare"
 tagprefix="uc1" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script src=http://www.codeproject.com/Scripts/jquery-1.4.1.min.js
 type="text/javascript"></script>
</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        A customizable Facebook Share button
    </h2>
    <p>
        <uc1:FacebookShare ID="FacebookShare1" runat="server"
  ApplicationId="12345" Message="Message"
            Name="Name" Caption="Caption" Description="Description"
  Href="http://mourfield.com"
            Image="http://www.gravatar.com/avatar/41e139e92663400389c2c9d95a865820.png" />
  </p>
    <p>
        You can also find <a href="http://developers.facebook.com/docs/"
            title="Facebook Developer Docs">documentation on Facebook at
  Facebook Developers</a>.
    </p>
</asp:Content>

ten you can set you properties within the page on page load event 十,您可以在页面上的页面加载事件中设置属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM