使用 jquery 将 facebook 页面提要作为 json 获取

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11926659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:05:39  来源:igfitidea点击:

get facebook page feed as json with jquery

jqueryfacebook-graph-apijsonp

提问by Foysal Ahamed

I have been trying to get facebook page feed from json data with jquery. so far I have been able to get page details with my method but when I try to get page's feed it gives me an error and in the console it says "syntax error: invalid label". this is my code.....

我一直在尝试使用 jquery 从 json 数据获取 facebook 页面提要。到目前为止,我已经能够使用我的方法获取页面详细信息,但是当我尝试获取页面的提要时,它给了我一个错误,并且在控制台中显示“语法错误:标签无效”。这是我的代码.....

    $.getJSON("https://www.facebook.com/feeds/page.php?id=237173582992285&format=json&callback=?", function(results){
    console.log(results);
});

I also have created a jsfiddle with the whole code. check it out if required -> http://jsfiddle.net/yZn7N/. I can see all the json data if I go to the specified link and they do get fetched and I'm not sure what's causing the invalid label error. Any kind of help fixing it or explanation of why this is happening will be gratefully appreciated.

我还用整个代码创建了一个 jsfiddle。如果需要,请查看 -> http://jsfiddle.net/yZn7N/。如果我转到指定的链接,我可以看到所有的 json 数据并且它们确实被获取,但我不确定是什么导致了无效标签错误。任何形式的帮助修复或解释为什么会发生这种情况将不胜感激。

回答by cpilko

Get rid of &callback=?from your URL. You have a result handler as part of your function. You don't need a callback.

摆脱&callback=?你的网址。您的函数中有一个结果处理程序。你不需要回调。

This shouldgive you the result you are looking for, but it appears that Facebook is blocking jsfiddle via an .htaccess policy.

应该会给你你正在寻找的结果,但似乎 Facebook 正在通过 .htaccess 策略阻止 jsfiddle。