Facebook OAuthException when posting to Wall for a Page

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):

<?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.

<?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.

Jeff Geerling is the owner of Midwestern Mac, LLC, and writes for this blog, his personal website (Life is a Prayer.com), and many other sites. He is an active contributor in the Drupal community, and has primarily been a Mac user since the 1990s. See more about the computers he has owned here: My Computing History.

Comments

Elvin's picture

Hey Jerry, could you please let me know which fields to you attach to the request? Because I am still getting "An error occured while creating the share" error

Pankaj Kumar Mishra's picture

Dear all, I am not PHP guy, but good in Java... I using Native API and APP access token to achieve Posting link, Feed or send notification to the user:

Following are links and their Parameter with Post Method:
To Post Link and Feed:
https://graph.facebook.com/USERID[0052....]/feed?access_token=AccessTOKE...

To Post Notification:
https://graph.facebook.com/...0052785.../notification?access_token=Acces...

Another Important reason why on get Error Code-1 unknown is:
When One set App from Web to Native/Desktop , he/she should set [App Secret in Client: to [No] ]

Add new comment