【发布时间】:2011-09-21 12:37:50
【问题描述】:
是的,我有一个问题,我已经做了很多研究,但我仍然无法解决这个问题。我想要实现的是当 facebook 用户喜欢我的页面而不是应用程序时,我希望能够检索所有喜欢 facebook 页面的用户。
我正在使用 FQL,但完全没有运气,如果我根据页面管理员执行 FQL,它会显示数据。
SELECT first_name, last_name FROM user WHERE uid IN (SELECT uid FROM page_fan WHERE page_id = [your page id])
上面的 FQL 应该可以工作。但是什么都没有显示,这是一个没有被标记或修复的 facebook 错误吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCFacebookTestApp.Models;
using Facebook;
using Facebook.Web;
namespace MVCFacebookTestApp.Controllers
{
public class HomeController : Controller
{
public FacebookSession FacebookSession
{
get { return (FacebookWebContext.Current.Session); }
}
public ActionResult Index()
{
string request = Request.Form["signed_request"];
string accessToken = "";
if (Request.Form["access_token"] != null)
{
accessToken = Request.Form["access_token"];
}
FacebookApplication app = new FacebookApplication();
FacebookSignedRequest result = FacebookSignedRequest.Parse(app.InnerCurrent, request);
if (String.IsNullOrWhiteSpace(accessToken))
{
accessToken = result.AccessToken;
}
dynamic data = result.Data;
bool liked = data.page.liked;
//bool liked = true;
if (!liked)
{
Home h = Home.NotLiked();
return View(h);
}
else
{
Home h = Home.Liked();
FacebookWebClient fb = null;
if (String.IsNullOrWhiteSpace(accessToken))
{
var fbRequest = FacebookWebContext.Current;
if (fbRequest.IsAuthorized())
fb = new FacebookWebClient(fbRequest);
}
else
{
fb = new FacebookWebClient(accessToken);
}
if (fb != null)
{
dynamic r = fb.Get("/me");
h.TestString2 += " Ha! We captured this data about you!";
h.TestString2 += " Name: " + r.name;
h.TestString2 += " Location: " + r.location;
h.TestString2 += " Birthday: " + r.birthday;
h.TestString2 += " About Me: " + r.aboutme;
h.ImgUrl = "http://graph.facebook.com/" + r.id + "/picture?type=large";
string fqlResult = "";
var fbApp = new FacebookClient(accessToken);
//basic fql query execution
dynamic friends = fbApp.Query("SELECT uid FROM page_admin WHERE page_id='160828267335555'");
//SELECT uid FROM page_fan WHERE page_id = 160828267335555
//"SELECT uid FROM page_fan WHERE uid=me() AND page_id=<your page id>";
//loop through all friends and get their name and create response containing friends' name and profile picture
foreach (dynamic friend in friends)
{
fqlResult += friend.uid + "<br />";
//fqlResult += friend.name + "<img src='" + friend.pic_square + "' alt='" + friend.name + "' /><br />";
}
ViewBag.Likes = fqlResult;
}
else
{
//Display a message saying not authed....
}
return View(h);
}
}
}
}
有没有真正有效的解决方案?请尽快回复我,您的帮助将不胜感激,这将使我免于因压力而失去所有头发 LOL
提前致谢。
【问题讨论】:
标签: facebook facebook-c#-sdk facebook-fql