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

发布于 2025-01-08 17:55:14 字数 1719 浏览 0 评论 0原文

有人可以告诉我如何获取帐户所有者在墙上发布的帖子吗?就我而言,我需要从我们公司 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.

谢谢, 拉维

Could someone please let me know how I can fetch posts posted by the account owner on the wall. In my case, I need to fetch posts from the wall of our company facebook page.

I have tried using the Graph API to fetch the results, but I have trouble fetching the access token.

To get Access Token, I have used the code below:

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;
}

To get UserData, I have used below:

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;
}

In my code, I make call to the Graph API as below:

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.

Thanks,
Ravi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文