ASP.NET Post to Facebook Wall

I am trying to post to a facebook wall without using an API like the C # Facebook SDK. I get the access token correctly and all that, but I get the 403 ban using the following code:

protected string postToWall()
{
    var accessToken = Session["_FB_ACCESS_TOKEN"];
    var graphId = Session["_FB_USER_GRAPH_ID"];

    var url = string.Format(
        "https://graph.facebook.com/{0}/feed",
        graphId
    );

    var req = WebRequest.Create(url);
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";

    string postData = string.Format(
        @"curl -F 'access_token={0}' -F 'message=This is a test...' https://graph.facebook.com/{1}/feed",
        accessToken,
        graphId
    );

    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    var stream = req.GetRequestStream();
    stream.Write(byteArray, 0, byteArray.Length);
    stream.Close();

    WebResponse response = req.GetResponse();
    Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    stream = response.GetResponseStream();
    StreamReader reader = new StreamReader(stream);

    return reader.ReadToEnd();
}
+2
source share
1 answer

You should not place curl -F ... as the body of a send request. curl is a command line utility that allows you to interact with http. Do you want to send a message https://graph.facebook.com/ {graphId} / feed? Access_token = {token}, with the message postData"= this test" replaces things in brackets with their values.

+1
source

All Articles