ASP.NET发布到Facebook Wall

我试图发布到Facebook墙, 而不使用像C#Facebook SDK这样的API。 我正确地获取了访问令牌以及所有这些,但我使用以下代码禁止403:

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(); } 

你不应该发布curl -F …作为post请求的主体。 curl是一个命令行实用程序,允许您与http进行交互。 您想发布到https://graph.facebook.com/ {graphId} / feed?access_token = {token},其中postData为“message = This is a test”,用括号替换括号中的内容。