如何在JavaScript中使用JSON格式读取Facebook Feed [英] How to read facebook feeds using json format in javascript

查看:97
本文介绍了如何在JavaScript中使用JSON格式读取Facebook Feed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是json格式的我的费用网址,此处

This is my fee url in json format here

我想知道如何使用jquery getJSON方法获取帖子内容,标题,喜欢,评论. 任何帮助都可以申请吗?

I want to know how to get the post content,title,likes,comment using jquery getJSON method. Any help woulld be appricated ?

JQUERY代码

$("document").ready(function() {
    $.getJSON("https://www.facebook.com/feeds/page.php?id=397319800348866&format=json", function(data) {
        $("#div-my-table").text("<table>");
        $.each(data, function(i, item) {
            $("#div-my-table").append("<tr><td>" + item.EncoderName + "</td><td>" + item.EncoderStatus + "</td></tr>");
        });
        $("#div-my-table").append("</table>");
    });
});

HTML代码

<table id="div-my-table">
    <tr><td></td></tr>
     <tr><td></td></tr>
     <tr><td></td></tr>
</table>

推荐答案

将jquery getJSON()与callback =一起使用?因此它将使用JSONP. 您必须使用一些API,例如graph graph.facebook.com 像下面这样.

Use jquery getJSON() with a callback=? so it will use JSONP. You must use some api like graph graph.facebook.com Something like the below.

$.getJSON('https://graph.facebook.com/397319800348866?callback=?', function(data) {
     console.log(data);
     $('#likes').text(data.likes);

})
.success(function() { console.log('success'); })
.error(function() { console.log('error'); })
.complete(function() { console.log('complete'); });​

HTML

 likes: <div id='likes'></div>​

这篇关于如何在JavaScript中使用JSON格式读取Facebook Feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆