Reputation: 1757
I have been playing around with the open graph api and more or so with the Publishing part as mentioned here
https://developers.facebook.com/docs/graph-api/using-graph-api/#publishing
It mentions For example, to publish a post on behalf of someone, you would make an HTTP POST request as below:
I require the UserID
and Access Token
.
So I have been able to get the Access Token
which doesn't expire and also the User ID
of the user that has accepted the app to publish content.
However to my failure I am unable to post feed by using the steps mentioned in the above link.
This is a small example I put together to test the HttpPost Request
[HttpPost]
public ActionResult FacebookPostResponse(string accessToken)
{
string fbPost = "Hello";
Uri targetUserUri = new Uri("https://graph.facebook.com/10153688496941651/feed?message=" + fbPost + "&access_token=" + accessToken);
HttpWebRequest post = (HttpWebRequest)HttpWebRequest.Create(targetUserUri);
HttpWebResponse res = (HttpWebResponse)post.GetResponse();
var sC = res.StatusCode;
ViewBag.Message = sC;
}
The ActionResult
above returns me a status code of OK
meaning the request was successful. However when I go to my facebook wall I don't see anything from the app?
When I copy the URL request in a web browser it returns the following:
{
"data": [
]
}
I am not sure what I am doing incorrect? Anybody have suggestions?
Upvotes: 0
Views: 183
Reputation: 46
You should set up your HttpWebRequest instance to use POST http method, the default value is GET
so just add this:
post.Method = "POST";
After :
HttpWebRequest post = (HttpWebRequest)HttpWebRequest.Create(targetUserUri);
Upvotes: 1