gpt4 book ai didi

javascript - '加载错误: unknown' when trying to delete apprequest in Javascript SDK

转载 作者:行者123 更新时间:2023-11-28 09:55:39 24 4
gpt4 key购买 nike

当我尝试使用 Javascript SDK 删除应用请求时,它会向 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>

我知道删除请求有效,因为我可以使用此网络表单手动删除请求:

<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 值的方式有问题。有人可以帮助我吗?

最佳答案

与 JavaScript SDK 对话:Facebooks' docs指出应该从点击事件中触发操作,以便所有浏览器都能正确显示任何弹出窗口(文档引用了 FB.login 函数,但该警告可能适用于其他调用) 。我想知道他们的 API 是否足够挑剔,需要一个有效的 href 属性(即使是短至 # 的属性)。

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

关于javascript - '加载错误: unknown' when trying to delete apprequest in Javascript SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10067110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com