I need to post on Facebook wall using Facebook c# sdk and mvc or asp.net web for开发者_如何学JAVAms are welcomed it will not be different and there is java script sdk is it will be good or using Facebook c# sdk is better
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 :
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 :
<%@ 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
精彩评论