从FaceBook页面获取帖子并在网站上显示

时间:2012-02-23 17:12:24

标签: c# facebook-graph-api

有人可以告诉我如何获取帐户所有者在墙上发布的帖子。在我的情况下,我需要从我们公司的Facebook页面的墙上获取帖子。

我已尝试使用Graph API获取结果,但我无法获取访问令牌。

要获取访问令牌,我使用了以下代码:

public string GetAccessToken()
{
string params = string.Format("grant_type=client_credentials&client_id={0}&client_secret={1}", this.ApplicationId, this.ApplicationSecret);
FacebookResponse response = this.IssueRequest(RequestAction.POST, "https://graph.facebook.com/oauth/access_token", params);
if ((response.HttpResponseCode == HttpStatusCode.OK) && (response.JSON != string.Empty))
{
this.AccessToken = response.JSON.Split(new char[] { '=' })[1];
}
return this.AccessToken;
}

要获取UserData,我使用了以下内容:

public string GetUserData(string UserId, UserConnection UC)
{
string uRL = string.Empty;
if (this.AccessToken != string.Empty)
{
uRL = string.Format("https://graph.facebook.com/{0}/{1}?access_token={2}", UserId, Common.GetStringValue(UC), this.AccessToken);
}
else
{
uRL = string.Format("https://graph.facebook.com/{0}/{1}", UserId, Common.GetStringValue(UC));
}
FacebookResponse response = this.IssueRequest(RequestAction.POST, uRL, string.Empty);
if ((response.HttpResponseCode == HttpStatusCode.OK) && (response.JSON != string.Empty))
{
return response.JSON;
}
return null;
}

在我的代码中,我调用了Graph API,如下所示:

FacebookGraphApi fg = new FacebookGraphApi();
FacebookGraphApi.FacebookUserFeed[] Feed =
FacebookGraphApi.ParseUserFeed(fg.GetUserData(ApplicationId, FacebookGraphApi.UserConnection.FEED));

//Bind results to Repeater
rptFacebookFeed.DataSource = Feed;
rptFacebookFeed.DataBind();


The ParseUserFeed returns FacebookUserFeed[] array.

谢谢, 拉维

0 个答案:

没有答案