Facebook API:获取喜欢页面的人的粉丝/ [英] Facebook API: Get fans of / people who like a page
问题描述
我想得到一个喜欢某个页面或者粉丝的用户列表。
I'd like to get a list of users who like a certain page or a fan of it.
FB API文档指出,您只能使用社交图表获取某个网页的粉丝的数量,但不能使用粉丝列表。
The FB API documentation states that you can only get the count of the fans of a certain page using the social graph, but not a list of the fans.
这里的讨论检索Facebook粉丝名称表明可以使用FQL查询,如 SELECT user_id FROM like WHERE object_id =您的页面ID
以获取喜欢该页面的人数,但是对于同一页面,它给出了一个空的响应{}
A discussion here Retrieve Facebook Fan Names suggests that one could use an FQL query like SELECT user_id FROM like WHERE object_id="YOUR PAGE ID"
to get the number of people who liked the page, but for the same page, it gives an empty response "{}".
所以我想知道是否有人有想法,如果这可以完成。
So I was wondering if anyone has an idea if this can be done.
推荐答案
有一种方式来获取一些粉丝列表的一部分,其中没有标记的个人资料ID。
There is a "way" to get some part of fan list with their profile ids of some fanpage without token.
-
获取有公开图形数据的粉丝专页的编号: http://graph.facebook.com/cocacola - 可口可乐有40796308305。更新2016.04.30 :Facebook now req使用访问令牌以通过图形获取page_id,以便您可以解析fanpage HTML语法来获取此ID,而无需任何https://www.facebook.com/ {PAGENAME}
的授权在下面的例子中,基于粉丝页面上的og标签。 - 获取可口可乐的like pluginiframe直接显示一些修改的参数: http://www.facebook.com/plugins/fan.php?connections=100&id=40796308305
- 现在查看页面来源,有很多粉丝拥有其个人资料的链接,您可以在其中找到他们的个人资料ID或昵称,如: http://www.facebook.com/michal.semeniuk 。
-
如果你只对配置文件ids有兴趣再次使用图表api - 它会直接给你个人资料ID: http://图.facebo ok.com/michal.semeniuk更新2016.04.30:Facebook现在需要访问令牌才能获取此类信息。您可以解析配置文件HTML语法,就像第一步元标记是您最好的朋友:
< meta property =al:android:urlcontent =fb:// profile / {PROFILE_ID}/>
Get id of a fanpage with public graph data: http://graph.facebook.com/cocacola - Coca-Cola has 40796308305.UPDATE 2016.04.30: Facebook now requires access token to get page_id through graph so you can parse fanpage HTML syntax to get this id without any authorization fromhttps://www.facebook.com/{PAGENAME}
as in example below based on og tags present on the fanpage.- Get Coca-Cola's "like plugin" iframe display directly with some modified params: http://www.facebook.com/plugins/fan.php?connections=100&id=40796308305
- Now check the page sources, there are a lot of fans with links to their profiles, where you can find their profile ids or nicknames like: http://www.facebook.com/michal.semeniuk .
If you are interested only in profile ids use the graph api again - it will give you profile id directly: http://graph.facebook.com/michal.semeniukUPDATE 2016.04.30: Facebook now requires access token to get such info. You can parse profile HTML syntax, just like in the first step meta tag is your best friend:<meta property="al:android:url" content="fb://profile/{PROFILE_ID}" />
现在是最好的部分:尝试刷新)点2中的链接..有一个新的可口可乐的另一个粉丝的全套。只有单一的,你可以得到一些很好的,几乎完整的粉丝列表。
And now is the best part: try to refresh (F5) the link in point 2.. There is a new full set of another fans of Coca-Cola. Take only uniques and you will be able to get some nice, almost full list of fans.
为什么不使用我的PHP脚本来获取一些粉丝? :)
Why don't you use my ready PHP script to fetch some fans? :)
更新2016.04.30 :更新了在Facebook开始需要访问令牌以从图形API获取公开数据后使用新方法的示例脚本
UPDATE 2016.04.30: Updated example script to use new methods after Facebook started to require access token to get public data from graph api.
function fetch_fb_fans($fanpage_name, $no_of_retries = 10, $pause = 500000 /* 500ms */){
$ret = array();
// prepare real like user agent and accept headers
$context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-encoding: gzip, deflate, sdch\r\nAccept-language: en-US,en;q=0.8,pl;q=0.6\r\n')));
// get page id from facebook html og tags for mobile apps
$fanpage_html = file_get_contents('https://www.facebook.com/' . $fanpage_name, false, $context);
if(!preg_match('{fb://page/(\d+)}', $fanpage_html, $id_matches)){
// invalid fanpage name
return $ret;
}
$url = 'http://www.facebook.com/plugins/fan.php?connections=100&id=' . $id_matches[1];
for($a = 0; $a < $no_of_retries; $a++){
$like_html = file_get_contents($url, false, $context);
preg_match_all('{href="https?://www\.facebook\.com/([a-zA-Z0-9\._-]+)" data-jsid="anchor" target="_blank"}', $like_html, $matches);
if(empty($matches[1])){
// failed to fetch any fans - convert returning array, cause it might be not empty
return array_keys($ret);
}else{
// merge profiles as array keys so they will stay unique
$ret = array_merge($ret, array_flip($matches[1]));
}
// don't get banned as flooder
usleep($pause);
}
return array_keys($ret);
}
print_r(fetch_fb_fans('TigerPolska', 2, 400000));
这篇关于Facebook API:获取喜欢页面的人的粉丝/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!