检索facebook api数据

时间:2013-08-02 15:26:33

标签: c# facebook-graph-api

我正在建立一个应该从Facebook检索新闻源的网站。但是,我的脚本最终在Newsfeed部分根本没有显示任何内容。我目前正在我的母版页标题中使用此代码:

<script src="http://code.jquery.com/jquery.min.js"></script>
<script>
    $(document).ready(function () {
        $.getJSON('http://graph.facebook.com/pyrotltu?fields=posts.limit(10).fields(message,picture,link,name,caption,description,likes,comments.fields(from,message,like_count,id),created_time,id)&callback=?', function (fbResults) {
            $.each(fbResults.data, function () {
                $('<article class="News"></article>').append(
                    '<div class="fbmessage">' + this.message + '</div>'
                    + '<a href="' + this.link + '">' + '<div class="fblink">' + '<img class="fbpicture" src="' + this.picture + '" height="90" width="90" alt="' + this.name + '" />' + '<div class="fbname">' + this.name + '</div>' + '<div class="fbcaption">' + this.caption + '</div>' + '<div class="fbdescription">' + this.description + '</div>' + '</div>' + '</a>'
                    + '<div class="fbcount">' + this.likes.count + '</div>'
                    + '<time class="fbtime" datetime=">' + this.created_time + '">' + this.created_time + '&middot;</time>'
                    + '<iframe class="fblike" src="http://www.facebook.com/plugins/like.php?href=' + this.link + '" ></iframe>'
                    + '<div class="fbcomments"></div>'
                        + $.each(fbResults.data.comment.data, function () {
                            $('<div class="Comments"></div>').append(
                            '<img class="fbcommentpic" src="https://graph.facebook.com/' + this.from.id + '/picture" height="50" width="50" alt="' + this.from.name + '" />'
                            + '<div class="fbcommentname"><a href="http://www.facebook.com/' + this.from.id + '">' + this.from.name + '</a></div>'
                            + '<div class="fbcommentmessage">' + this.message + '</div>'
                            + '<div class="fblike_count">' + this.like_count + '</div>'
                            ).appendTo('.fbcomments');
                        })
                 ).appendTo('.Newsfeed');
            })
        })
    });
</script>

要获取我使用的访问令牌:

protected void Page_Load(object sender, EventArgs e)
{

    string appId = ConfigurationManager.AppSettings["facebook:AppID"];
    string appSecret = ConfigurationManager.AppSettings["facebook:AppSecret"];

    var fb = new Facebook.FacebookClient();

    dynamic tokenInfo =
      fb.Get(
        String.Format(
          "/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials",
          appId,
          appSecret));

    var appAccessToken = (string)tokenInfo.access_token;

}

(ID和密码存储在我的Web.config中)

此代码有什么缺失或错误?

0 个答案:

没有答案