Programing

Facebook API : 페이지를 좋아하는 사람 / 팬 확보

crosscheck 2020. 11. 8. 09:18
반응형

Facebook API : 페이지를 좋아하는 사람 / 팬 확보


특정 페이지를 좋아하거나 팬이있는 사용자의 목록을 얻고 싶습니다.

FB API 문서에 따르면 소셜 그래프를 사용하여 특정 페이지의 팬 수만 가져올 수 있지만 팬 목록은 확인할 수 없습니다.

Retrieve Facebook Fan Names 의 토론 은 FQL 쿼리를 사용 SELECT user_id FROM like WHERE object_id="YOUR PAGE ID"하여 페이지를 좋아하는 사람 수를 가져올 수 있다고 제안 하지만 동일한 페이지에 대해 빈 응답 "{}"을 제공합니다.

그래서이 일을 할 수있는 사람이 있는지 궁금합니다.


토큰이없는 일부 팬 페이지의 프로필 ID로 팬 목록의 일부를 가져 오는 "방법"이 있습니다.

  1. 공개 그래프 데이터로 팬 페이지의 ID 가져 오기 : http://graph.facebook.com/cocacola-Coca-Cola 에는 40796308305 가 있습니다. 2016.04.30 업데이트 : Facebook은 이제 그래프를 통해 page_id를 가져 오려면 액세스 토큰이 필요하므로 팬 페이지 HTML 구문을 구문 분석 할 수 있습니다. https://www.facebook.com/{PAGENAME}팬 페이지에있는 og 태그를 기반으로 아래 예와 같이 승인없이이 ID를 가져옵니다 .
  2. 일부 수정 된 매개 변수를 사용하여 Coca-Cola의 "like plugin"iframe 디스플레이를 직접 가져옵니다. http://www.facebook.com/plugins/fan.php?connections=100&id=40796308305
  3. 이제 페이지 소스를 확인하세요. 프로필에 대한 링크가있는 많은 팬이 있습니다. 여기에서 프로필 ID 나 닉네임을 찾을 수 있습니다. http://www.facebook.com/michal.semeniuk .
  4. 프로필 ID에만 관심이있는 경우 그래프 API를 다시 사용하세요. 프로필 ID를 직접 제공합니다. http://graph.facebook.com/michal.semeniuk 업데이트 2016.04.30 : Facebook은 이제 이러한 정보를 얻으려면 액세스 토큰이 필요합니다. 첫 번째 단계에서 메타 태그가 가장 친한 친구 인 것처럼 프로필 HTML 구문을 구문 분석 할 수 있습니다.<meta property="al:android:url" content="fb://profile/{PROFILE_ID}" />

그리고 지금은 가장 중요한 부분입니다. 2 번 지점의 링크를 새로 고치십시오 (F5). Coca-Cola의 또 다른 팬의 새로운 전체 세트가 있습니다. 고유 항목 만 가져 오면 멋지고 거의 전체 팬 목록을 얻을 수 있습니다.

-업데이트 2013.08.06-

내 준비된 PHP 스크립트를 사용하여 일부 팬을 불러 오지 그래요? :)

UPDATE 2016.04.30 : Facebook이 그래프 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\._-]+)" class="link" 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));

새로운 페이스 북 검색을 사용하여 팬을 확보 할 수 있습니다 : https://www.facebook.com/search/321770180859/likers?ref=about


이것을 사용하십시오.

https://www.facebook.com/browse/?type=page_fans&page_id=<your page id>

가장 최근의 좋아요를 최대 500 개까지 반환합니다.

http://www.facebook.com/browse/?type=page_fans&page_id=<your page id>&start=400

각 페이지는 100 명의 팬을 제공합니다. 시작 값을 (0, 100, 200, 300, 400)으로 변경하여 처음 500 개를 얻습니다. 시작이> = 401이면 페이지가 비어 있습니다.


Facebook 문서 에 따르면 페이지의 모든 팬을 확보하는 것은 불가능합니다.

Facebook 페이지의 모든 팬 목록을 가져올 수는 없지만 특정 사용자가 페이지를 좋아했는지 여부를 확인할 수 있습니다.


s3m3n의 답변에 대해 Facebook 팬 플러그인 (예 : LAMODA )에는 이제 제한이 있습니다. 지속적인 요청에 대한 새로운 팬이 점점 줄어들고 있습니다. 결과를 시각화하기 위해 수정 된 PHP 스크립트를 사용해 볼 수 있습니다 : https://gist.github.com/liruqi/7f425bd570fa8a7c73be#file-facebook_fans_by_plugin-php

또 다른 접근 방식은 Facebook 그래프 검색입니다. 검색 결과 페이지 : 'Lamoda'페이지를 좋아하는 사용자는 Chrome 콘솔을 열고 자바 스크립트를 실행합니다.

var run = 0;
var mails = {}
total = 3000; //滚动次数,可以自己根据情况定义

function getEmails (cont) {
    var friendbutton=cont.getElementsByClassName("_ohe");
    for(var i=0; i<friendbutton.length; i++) {
        var link = friendbutton[i].getAttribute("href");

        if(link && link.substr(0,25)=="https://www.facebook.com/") {
            var parser = document.createElement('a');
            parser.href = link;
            if (parser.pathname) {
                path = parser.pathname.substr(1);
                if (path == "profile.php") {
                    search = parser.search.substr(1);
                    var args = search.split('&');
                    email = args[0].split('=')[1] + "@facebook.com\n";
                } else {
                    email = parser.pathname.substr(1) + "@facebook.com\n";
                }
                if (mails[email] > 0) {
                    continue;
                }
                mails[email] = 1;
                console.log(email);
            }
        }
    }
}

function moreScroll() {
    var text="";
    containerID = "BrowseResultsContainer"
    if (run > 0) {
        containerID = "fbBrowseScrollingPagerContainer" + (run-1);
    }
    var cont = document.getElementById(containerID);
    if (cont) {
        run++;
        var id = run - 2;
        if (id >= 0) {
            setTimeout(function() {
                containerID = "fbBrowseScrollingPagerContainer" + (id);
                var delcont = document.getElementById(containerID);
                if (delcont) {
                getEmails(delcont);
                delcont.parentNode.removeChild(delcont);
                }
                window.scrollTo(0, document.body.scrollHeight - 10);
            }, 1000);
        }
    } else {
        console.log("# " + containerID);
    }
    if (run < total) {
        window.scrollTo(0, document.body.scrollHeight + 10);
    }
    setTimeout(moreScroll, 2000);
}//1000为间隔时间,也可以根据情况定义

moreScroll();

새 팬을로드하고 사용자 ID / 이메일을 인쇄하고 페이지 충돌을 방지하기 위해 이전 DOM 노드를 제거합니다. 이 스크립트는 여기에서 찾을 수 있습니다.


이 페이지는 https://developers.facebook.com/docs/reference/fql/like/ 썼지 만 팬 목록을 얻을 수 없습니다.

"The Post, Video, Note, Link, Photo and Album Graph API objects contain an equivalent connection called likes."

NOTE: fql like query is deprecated


Technically this FQL query should work, but for some reason Facebook disallows it because of a missing index. Not sure if that is because of policy or they just forgot.

SELECT uid FROM page_fans WHERE page_id="YOUR_PAGE_ID"

Facebook's FQL documentation here tells you how to do it. Run the example SELECT name, fan_count FROM page WHERE page_id = 19292868552 and replace the page_id number with your page's id number and it will return the page name and the fan count.

참고URL : https://stackoverflow.com/questions/4018849/facebook-api-get-fans-of-people-who-like-a-page

반응형