1

Javascript SDK を使用してアプリ リクエストを削除しようとすると、「load-error: unknown」というエラー オブジェクトが FireBug に返されます。

これは、PHP と JS SDK の両方を使用したテスト アプリです。

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

このウェブフォームを使用してリクエストを手動で削除できるため、deleteRequest が機能することはわかっています。

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

このメソッドは、FireBug に「true」を返します。

onClick 値の書き方に問題があると思います。誰かが私を助けることができますか?

4

1 に答える 1

0

JavaScript SDK について: Facebook のドキュメントでは、すべてのブラウザーでポップアップが適切に表示されるように、アクションはクリック イベントから起動する必要があると指摘されています (ドキュメントではFB.login関数について言及していますが、その警告は他の呼び出しにも適用される可能性があります)。彼らの API は、有効なhref属性 ( #.

Facebook のサーバーに対して複数の非同期リクエストが保留されている場合の正確なエラーも確認しました。コードで別のリクエストが処理中で、delete 呼び出しがそれを妨害している可能性はありますか?

于 2012-04-26T15:39:06.557 に答える