从 Facebook 页面获取帖子并显示在网站上
有人可以告诉我如何获取帐户所有者在墙上发布的帖子吗?就我而言,我需要从我们公司 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论