I already have authenticated users in OAuth. I have my app-id, my access token which I extended. Facebook recently updated their Graph Api to v3.1. I have searched all over the net but no luck. How can i get the post in my Create-Post controller to save both to my database and post to facebook as well. Posting as a page or post to user wall examples would be great, in ASP.NET Core MVC Please.
I have tried everything on the web but nothing works. I have removed the edits on my post controller so it can only store the user-post to my database for now. Please help, how can I tackle this problem good people.
//post create post
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Post post)
{
string url = "http://graph.facebook.com/v3.1/";
string myAppID = "my_app_id";
string myAccessToken = "my_access_token";
if (ModelState.IsValid)
{
_db.Add(post);
await _db.SaveChangesAsync();
return RedirectToAction(nameof(Index), new { userId = post.UserId });
}
return View(post);
2
Answers
Good-day fellow developers. In case any of you out there are still experiencing problems posting to Facebook from your .NET Core 2.0 applications here is the solution.
First of all, the documentation from Facebook is very misleading(for myself it was). It turns out that the actual access token you need is the Page Access Token. You do not need app access token/user access token when doing queries to the API all you need is the page access token. This of-course works only if you are the Application and page admin no need for App Review at this point. I hope you figure out how to extend this access token to never expire here
This is how you use it on your controller:
I also had the same problem after my website was not approved to publish_pages on Facebook.
I would recommend that you try using a javascript SDK to do that, it helped me while I was facing difficulties with .NET-core. This link might help you:
https://developers.facebook.com/docs/javascript/quickstart
This will be just for loading of the SDK, you will still need a getInfo function and a post function. This how I did it, try it and see how it goes. All the best.