我正在尝试阅读我的应用评论,但我不知道怎么做?没有正确/完整的样本。
[CanvasAuthorize(Permissions = "user_about_me")]
public ActionResult About()
{
var client = new FacebookWebClient(FacebookWebContext.Current.AccessToken);
dynamic result = client.Get("19292868552_118464504835613/comments");
ViewBag.result = result;
}
并在视图中,尝试阅读:
foreach (dynamic comment in ViewBag.result)
{
@comment.id
<text><br /></text>
}
请帮助我如何阅读在MVC应用程序中为Facebook页面输入的用户评论。
答案 0 :(得分:0)
如您所知,在Facebook中,您可以创建自己的页面,该页面在URL中有ID。 以下是控制器的代码:
[CanvasAuthorize(Permissions = "user_about_me")]
public ActionResult Comments()
{
var client = new FacebookWebClient(FacebookWebContext.Current.AccessToken);
dynamic feeds = client.Get("{PageID}/feed");
ViewBag.feeds = feeds;
return View();
}
以及您的观看代码:
<table>
@foreach (dynamic myFeed in ViewBag.feeds.data)
{
if (myFeed.type == "status" && myFeed.from.id != "{PageID}")
{
<tr>
<td>
<img src="@HomeController.GetPictureUrlSmall(myFeed.from.id)" />
</td>
<td>
<span style="font-weight: bold;">@myFeed.from.name</span><br />
@myFeed.message
</td>
</tr>
}
}
</table>
@{
string strNext = ViewBag.feeds.paging.next;
string strPrevious = ViewBag.feeds.paging.previous;
}
<a href="@strPrevious" >Previous</a>
<br />
<a href="@strNext" >Next</a>
获取用户照片的功能:
public static string GetPictureUrlSmall(string faceBookId)
{
WebResponse response = null;
string pictureUrl = string.Empty;
try
{
WebRequest request = WebRequest.Create(string.Format("http://graph.facebook.com/{0}/picture?type=small", faceBookId));
response = request.GetResponse();
pictureUrl = response.ResponseUri.ToString();
}
catch (Exception ex)
{
//? handle
}
finally
{
if (response != null) response.Close();
}
return pictureUrl;
}
我希望它对一些开发人员有所帮助,但我仍然有分页问题。我没有找到一个方便的解决方案。谢谢,佩德拉姆