Facebook OAuthException when posting to Wall for a Page

⚠️ Warning
This post is more than 10 years old. I do not delete posts, because even old information is still useful, but please know that some material on this page may be outdated or incorrect. Thanks!
Sep 17, 2012

I integrate Facebook posting with a few different websites and services, so I've gotten to know Facebook's Open Graph and API pretty well over the past few years. A lot of sites I work with automatically post new stories straight to a Facebook Page's wall, and have a format with a message and an attached link. All of these parameters are well documented in Facebook's API under Post.

However, lately I've been getting the following error message whenever a site uses the first method below to send a post with a link attached:

{
  "message" : "An unknown error has occurred.",
  "type" : "OAuthException",
  "code" : 1
}

I tried using the Open Graph Explorer, the official Facebook SDK for PHP, and other methods to see if there was any other way to get around that exception, but nothing I did turned out any different response.

Here's how I sent a typical request with just a link (just using plain-vanilla PHP with cURL):

<code>
<?php
  // Set up params to be posted to Facebook.
  $params = array(
    'title' => $title,
    'link' => $url,
    'description' => $link_description,
    'caption' => $link_caption,
    'access_token' => FACEBOOK_APP_ID . '|' . FACEBOOK_APP_SECRET,
  );
  // Post the message to Facebook.
  $url = 'https://graph.facebook.com/' . FACEBOOK_PAGE_ID . '/feed';
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, count($params));
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  $result = curl_exec($ch);
  curl_close($ch);
?>

Now, to get the message to post without throwing the strange OAuthException, I have to send everything in the 'message' of the post (with no link attached). You can pass along other params, but if you pass anything in the 'link' param, you'll get the error at the top of this post.

<code>
<?php
  // Set up params to be posted to Facebook.
  $params = array(
    'message' => $title . ' — ' . substr($description, 0, 350) . '...' . "\r\n\r\n" . 'Source: ' . $url,
    'access_token' => FACEBOOK_APP_ID . '|' . FACEBOOK_APP_SECRET,
  );
?>

There's an open bug for this on Facebook's Developers site, but it's been triaged as 'low priority', so I don't know if it'll ever be fixed. I just wanted to post this so any other frustrated developers don't have to spend a few hours scratching their heads over the same issue.