0
votes

I am having a post id, and i want to comment on that post using c#. I am using the Facebook SDK 6.4.2. Now while using the graph explorer i am able to comment like

postid/comments?message=Commented using graph api explorer"

In c# I am doing as below

var client = new FacebookClient(accesstoken);
var parameters = new Dictionary<string, object>
                    { 
                         { "message", "hi! this is my status message" },
                         { "place",postid}
                    };
client.Post("me/feed", parameters);

It is showing the error:(OAuthException - #1) An unknown error has occurred.

1
What is the error message? - glautrou
The error message is (OAuthException - #1) An unknown error has occurred. - Furquan Khan
Thanks, I think for such things you need to use the OAuth token of your user to post a comment, otherwise everybody will be able to post comments for all users in FB. If it still doesn't work look at your Facebook App configuration, you can enable this. - glautrou
I am trying to comment on a post on my page(I am the admin) i have the access token with full permissions - Furquan Khan
Ok, I never used the C# API but I guess you have to provide the OAuthToken and OAuhtSecret to your var client. That's why you get the OAuth exception. Is it an ASP.Net application> - glautrou

1 Answers

1
votes

Like the error message says, you need to use OAuth tokens to publish comments on Facebook.

Obtaining tokens:

For obtaining those tokens you need to redirect your user to Facebook end get response tokens.Once authenticated in Facebook your user will be redirected to your application and then you can store those tokens provided by Facebook in your database if you want.

Authorization:

I cannot find the documentation of your SDK, but according to the JavaScript SDK documentation (section "Creating comments and replies"):

Permissions

This call must be made with publishing permission and a valid access_token. The token should be from a person or page that is allowed to comment on the parent object on Facebook. In order to create a comment as a Page, a page access token is required.

It says that your need both "publishing permission" and "publishing permission". For your SDK parameters name could be differents but the principle is the same.

To summarize you need the approval of the user (obtaining tokens) and post on his behalf (authorization).