使用 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
get facebook page feed as json with jquery
提问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 Adrian Salazar
You need to use the Facebook Graph API for this to happen.
您需要使用 Facebook Graph API 来实现这一点。
https://developers.facebook.com/docs/reference/api/page/#feed
https://developers.facebook.com/docs/reference/api/page/#feed
Your call should change to:
您的呼叫应更改为:
https://graph.facebook.com/237173582992285/feed?access_token=YOUR-TOKEN-GOES-HERE
https://graph.facebook.com/237173582992285/feed?access_token=YOUR-TOKEN-GOES-HERE
You can try use this test page and try to familiarize with the graph api.
您可以尝试使用此测试页面并尝试熟悉图形api。
https://developers.facebook.com/tools/explorer/?method=GET&path=237173582992285%2Ffeed
https://developers.facebook.com/tools/explorer/?method=GET&path=237173582992285%2Ffeed
EDIT:
编辑:
You can also get the Wall from the page in several formats.
您还可以从页面以多种格式获取墙。
JSON https://www.facebook.com/feeds/page.php?format=json&id=237173582992285
JSON https://www.facebook.com/feeds/page.php?format=json&id=237173582992285
ATOM https://www.facebook.com/feeds/page.php?format=atom10&id=237173582992285
ATOM https://www.facebook.com/feeds/page.php?format=atom10&id=237173582992285
RSS https://www.facebook.com/feeds/page.php?format=rss20&id=237173582992285
RSS https://www.facebook.com/feeds/page.php?format=rss20&id=237173582992285
回答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。