我试图在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();
}
答案 0 :(得分:1)
你不应该发布curl -F ...作为帖子请求的正文。 curl是一个命令行实用程序,允许您与http进行交互。您想发布到https://graph.facebook.com/ {graphId} / feed?access_token = {token},postData
为“message =这是一个测试”,用括号替换括号中的内容。