【问题标题】:get likers of Facebook page and get count of those who like more than 200 pages在 Facebook 页面上获得喜欢并计算喜欢超过 200 个页面的人
【发布时间】:2016-02-03 18:18:54
【问题描述】:

我正在尝试获取关注 Facebook 页面的随机喜欢者的“列表”。我正在使用此代码来吸引一些粉丝(不是随机粉丝,但这是另一回事)。

<?php
function fetch_fb_fans($fanpage_name, $no_of_retries = 10, $pause = 500000){
    $ret = array();
    /* get page info from graph */
    $fanpage_data = json_decode(file_get_contents('http://graph.facebook.com/' . $fanpage_name), true);
    if(empty($fanpage_data['id'])){
        /* invalid fanpage name */
        return $ret;
    }
    $matches = array();
    $url = 'http://www.facebook.com/plugins/fan.php?connections=100&id=' . $fanpage_data['id'];
    $context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0')));
    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('cocacola', 2, 400000));
prints 73 unique fan names as array
*/

$contador = 0;
foreach (fetch_fb_fans('cocacola', 2, 400000) as $fan) {


    $pageContent = file_get_contents('http://graph.facebook.com/'.$fan.'');
    $parsedJson  = json_decode($pageContent);
    echo $parsedJson->username ."<br/>";
}
?>

代码来自:Facebook API: Get fans of / people who like a page

这段代码给了我一些用户名。现在,我的问题是,在搜索谷歌之后......我可以得到每个用户关注的页面数吗?

我知道Graph API 让我知道我的喜好,但是当我尝试查看其他用户的喜好时,它会抛出 OAuthException 错误。我想我做得不对。 因此,我将对如何执行此操作进行一些解释。我搜索了 Google,但我不明白它是如何工作的。

谢谢。

【问题讨论】:

  • 不允许抓取 Facebook

标签: facebook facebook-graph-api facebook-like facebook-page


【解决方案1】:

遗憾的是,Facebook 文档不是很清楚:https://developers.facebook.com/docs/graph-api/reference/v2.2/user

但是,从用户那里获得喜欢需要:

  • 用户的用户访问令牌
  • 在访问令牌上授予“用户点赞权限”,这是 Facebook 在您的应用上批准的特殊权限

如果没有用户的访问令牌,您将无法看到他们喜欢哪些页面。

虽然不受支持,但如果他们公开了这些信息,您或许可以使用页面抓取工具来查找此信息。

根据您的问题,尚不清楚用户是登录您的应用还是您只是想从您自己的一个页面或另一个页面获取信息。如果您没有用户登录您的应用,恐怕除了页面抓取之外根本无法获取这些信息。

【讨论】:

  • 那么,如果用户不登录我的应用程序,我就无法获取该信息,对吧?
猜你喜欢
  • 1970-01-01
  • 2013-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-01
相关资源
最近更新 更多