1

When I try to delete an app request using the Javascript SDK, it returns an error object to FireBug saying: "load-error: unknown."

This is a test app using both PHP and JS SDKs.

<?php

// This loads the PHP SDK and pulls a user's apprequests
require 'fb-sdk/facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'APP_ID',
  'secret' => 'APP_SECRET',
));
$user = $facebook->getUser();
if ($user) {
  try {
    $user_profile = $facebook->api('/me');
    $user_requests = $facebook->api('/me/apprequests');
    $apprequests = $user_requests['data'];
  } catch (FacebookApiException $e) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}
?>

// This spits out a table of requests with links to delete them.
// The table doesn't reload when you delete a request so you have to refresh.
<table>
<?php foreach ($apprequests as $apprequest) { ?>
  <tr>
  <td><a href="" onClick="deleteRequest('<?php echo $apprequest['id']; ?>')">Delete</a></td>
  </tr>
<?php } ?>
</table>

// This loads the JS SDK and makes a function to delete requests.
<script>
function deleteRequest(requestId) {
  FB.api('/' . requestId, 'delete', function (response) {
    console.log(response);
    // Will have a function to reload the table...
  });
}
window.fbAsyncInit = function() {
  FB.init({
    appId: '<?php echo $facebook->getAppID() ?>',
    cookie: true,
    xfbml: true,
    oauth: true
  });
};
(function() {
  var e = document.createElement('script'); e.async = true;
  e.src = document.location.protocol +
    '//connect.facebook.net/en_US/all.js';
  document.getElementById('fb-root').appendChild(e);
}());
</script>

I know the deleteRequest works because I can delete a request manually using this webform:

<input type="text" name="manReqId"></text>
<input type="button"
  onClick="manDelRequest(); return false;"
  value="Delete request"
/>
<script>
function manDelRequest () {
  deleteRequest(document.getElementsByName("manReqId")[0].value);
}
</script>

This method returns "true" to FireBug.

I'm assuming there's something wrong with the way I write the onClick value. Can someone help me?

1 Answers1

0

Speaking to the JavaScript SDK: Facebooks' docs point out that actions should be be fired from click events, so that any popups will be shown properly for all browsers (the docs reference the FB.login function, but that warning may be applicable to other calls). I wonder if their API is finicky enough that it requires a valid href attribute (even one as short as #).

I have also seen that exact error when multiple asynchronous requests are pending against Facebook's servers. Is it possible that your code has another request in process, and the delete call interferes with it?

tephyr
  • 1,001
  • 2
  • 14
  • 26