1

当我尝试使用JavaScript SDK删除应用程序请求时,它向FireBug返回一个错误对象,内容如下:“load-error:unknown”。尝试删除Javascript SDK中的apprequest时出现'load-error:unknown'

这是一个同时使用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> 

此方法返回“真”到萤火虫。

我假设我写onClick值的方式有问题。有人能帮我吗?

回答

0

说到的JavaScript SDK:Facebooks' docs人指出,行动应从点击事件被解雇,因此任何弹出窗口将正常显示所有浏览器(文档引用的FB.login功能,但警告可能适用于其他调用)。我不知道他们的API是否足够挑剔,它需要一个有效的href属性(即使是一个简短的#)。

我也看到,当多个异步请求挂起对Facebook的服务器时,确切的错误。是否有可能您的代码有另一个请求正在处理,并且删除调用会干扰它?

相关问题