Post a comment on facebook wall using asp.net

I have a website that I registered as a facebook app. Now I have an application id.

My site is ASP.net C #. When a user clicks a button, I would like him to post a predefined message on the wall. I expect Facebook to present the user with a login dialog - they will log in and provide permission to publish for my web application.

Does anyone have sample code that would do this? I think I need to use the graphical API, but all the examples I've seen use PHP, which I know nothing about. I am looking for an example that will use Java Script (which I know almost nothing) or C # (beautiful!).

* Update *

I managed to get access_token. Now I am calling through the C # Facebook API to post it to the wall. I get an error message:

(# 803) Some of the aliases you requested do not exist: profile_id

I went through the api code and found that he was trying to send a message to the following address: { https://graph.facebook.com/PROFILE_ID/feed }, message data is: message = Example + message + from + c% 23 + sdk & access_token = 199209316768200 | 2.1avFTZuDGR4HJ7jPFeaO3Q __. 3600.1302897600.1-100000242760733 | R4DkNDf4JCb6B2F64n5TSQwBqvM

I am sure my token must be valid. Before requesting an access token, I requested publish_stream for an application authorization request as follows:

Response.Redirect ("https://www.facebook.com/dialog/oauth?client_id=" + myAppId + "&redirect_uri=" + myURL + "&scope=publish_stream");

The sdk code that actually makes the request looks like this:

private string MakeRequest(Uri url, HttpVerb httpVerb,
                                   Dictionary<string, string> args)
        { 
        if (args != null && args.Keys.Count > 0 && httpVerb == HttpVerb.GET)
        {
            url = new Uri(url.ToString() + EncodeDictionary(args, true));
        }

        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

        request.Method = httpVerb.ToString();

        if (httpVerb == HttpVerb.POST)
        {
            string postData = EncodeDictionary(args, false);

            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] postDataBytes = encoding.GetBytes(postData);

            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postDataBytes.Length;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(postDataBytes, 0, postDataBytes.Length);
            requestStream.Close();
        }

        try
        {
            using (HttpWebResponse response 
                    = request.GetResponse() as HttpWebResponse)
            {
                StreamReader reader 
                    = new StreamReader(response.GetResponseStream());

                return reader.ReadToEnd();
            }
        }

- , ?

,

Rob.

+5
5
+2

.NET, ​​ http://facebooknet.codeplex.com/. , ...

.

+1

, , , OG: http://www.markhagan.me/Samples/Grant-Access-And-Post-As-Facebook-User-ASPNet

, :

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Facebook;

namespace FBO
{
    public partial class facebooksync : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckAuthorization();
        }

        private void CheckAuthorization()
        {
            string app_id = "374961455917802";
            string app_secret = "9153b340ee604f7917fd57c7ab08b3fa";
            string scope = "publish_stream,manage_pages";

            if (Request["code"] == null)
            {
                Response.Redirect(string.Format(
                    "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                    app_id, Request.Url.AbsoluteUri, scope));
            }
            else
            {
                Dictionary<string, string> tokens = new Dictionary<string, string>();

                string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
                    app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);

                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());

                    string vals = reader.ReadToEnd();

                    foreach (string token in vals.Split('&'))
                    {
                        //meh.aspx?token1=steve&token2=jake&...
                        tokens.Add(token.Substring(0, token.IndexOf("=")),
                            token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                    }
                }

                string access_token = tokens["access_token"];

                var client = new FacebookClient(access_token);

                client.Post("/me/feed", new { message = "markhagan.me video tutorial" });
            }
        }
    }
}
+1

API, , Facebook.

.

Imports Branches.FBAPI
...
Dim SI As New SessionInfo("[application_id]","applicaiton_secret")
'Redirects user to facebooks
SI.AuthenticateUser("http://[my url]", New SessionInfo.PermissionsEnum(){SessionInfo.PermissionsEnum.email, SessionInfo.PermissionsEnum.read_stream}))
'Called when the user is returned to your page
Dim FSR = FS.ReadFacebooAuthResponse
Response.Write(FSR.Access_Token)
Response.Write(FSR.UserID)

Imports Branches.FBAPI
...
Dim SI As New SessionInfo("[access_token]"))
Dim Posts = New Functions.Posts(SI)
Dim P As New Post
P.name = "name of post"
P.message = "message"
P.link = "www.cnn.com"
P.caption = "my caption"
Posts.PublishCreate("[object ID to post to]", P)
Dim PostID = P.id

.

Dim SI As New SessionInfo("[access_token]"))
Dim Req New Functions.Requests(SI)
Dim User = Req.GetUserInfo("[optional user ID]")
Response.Write(U.name)
0

All Articles