开发者

ASP.NET Post to Facebook Wall

I'm trying to post to a facebook wall, without using an API such as the C# Facebook SDK. I'm correctly getting the access token and all that, but I'm getting a 403 forbidden 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, byteArr开发者_高级运维ay.Length);
    stream.Close();

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

    return reader.ReadToEnd();
}


You shouldn't be posting curl -F... as the body of the post request. curl is a command line utility that allows you to interact with http. You want to post to an https://graph.facebook.com/{graphId}/feed?access_token={token} with the postData being "message=This is a test" replacing things in brackets with their values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜