gpt4 book ai didi

javascript - 如何从 Facebook 评论插件获取评论

转载 作者:行者123 更新时间:2023-11-28 00:42:41 25 4
gpt4 key购买 nike

我按照本指南在发表评论时触发一个函数。目前,我可以在发表评论时进行 ajax 调用来与我的数据库进行交互。

FB Comments Plugin - Detect comment on page

我想要做的是每次发表评论时将评论的副本保存在我自己的数据库中。我不确定我想永远使用 Facebook 评论,所以我想将所有数据保存在我的数据库中,以防我恢复到原来的评论系统。

我尝试使用 jquery 从文本框中获取值并从范围中获取用户名。

var comment = $('.mentionsTextarea').val();
var username = $('.commentasName').html();

这段代码没有获取到数据。我猜是因为它位于 iframe 内。我想知道当评论提交被触发时是否可以从实际对象中获取数据。那么当事件被触发时我可以从评论对象中获取数据吗?像这样的东西。

FB.Event.subscribe('comment.create',
function(response) {
var comment = comment.text();
var username = comment.username.text();
}

最佳答案

我没有想要的答案,但我确实有一个解决方案。这将获取针对特定网址的最新评论。

$comments = file_get_contents('https://graph.facebook.com/comments/?ids='.$url);
$comments = json_decode($comments, true);
$comments = $comments[$url]['comments']['data'];
$latestComment = $comments[0];
$username = $latestComment['from']['name'];
$message = $latestComment['message'];
echo $username ." - ".$message;

关于javascript - 如何从 Facebook 评论插件获取评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27765799/

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