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, byteArray.Length);
stream.Close();
WebResponse response = req.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
return reader.ReadToEnd();
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0