Search code examples
c#asp.net-mvcfacebookfacebook-graph-apifacebook-c#-sdk

How come I suddenly start receiving OAuthException when posting to facebook page using facebook c# SDK


Thanks for the help. I am having some troubles posting a link to a facebook page. It gets called from a MVC website running an Umbraco installation. To post I am using the official facebook SDK for the .NET framework.

It worked perfectly the last 6 months until I started receiving the following error: "(OAuthException - #2) An unexpected error has occurred. Please retry your request later." And the full stack trace:

   at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, String responseString, Type resultType, Boolean containsEtag, IList`1 batchEtags)
   at Facebook.FacebookClient.Api(HttpMethod httpMethod, String path, Object parameters, Type resultType)
   at Facebook.FacebookClient.Post(String path, Object parameters)
   at WebsiteFixit.BLL.FacebookPoster.Post(String message, String link, Int32 newsItemId) in d:\Users\Documents\Freelance\Cereus\Fixit Website On Launch\Fixit Website_SVN\WebsiteFixit.BLL\FacebookPoster.cs:line 41

I find it rather awkward because nothing has changed on the code and it suddenly stopped working. I use the following code to post a link onto a facebook page via the graph api:

var fb = new FacebookClient();    
dynamic result = fb.Post(PageId + "/links", new
                {
                    access_token = AccessToken,
                    link = url,
                    message = message
                });

It's returning this error for a full month now. I didn't know what to do. Does anyone have solution for this problem?

Edit: I have checked the validity of my accesstoken through the Graph API Explorer.


Solution

  • The solution to the problem was the link to where the post happened. Because of a change in the Graph API the it should be posted to /feed var fb = new FacebookClient();

    dynamic result = fb.Post(PageId + "/feed", new
                    {
                        access_token = AccessToken,
                        link = url,
                        message = message
                    });