M
M
Msim2015-10-29 23:11:47
PHP
Msim, 2015-10-29 23:11:47

How does vk behave when parsed?

How vk behaves when parsing, the essence is that you need to select all users from the group simply by links to their aki, and worked on the api to pull articles from the group, but here is the case when not the creator of the group wants to do this.
UPD implemented the function of selecting groups and meeting in a txt file of all users. The code is not very good, don't shout, but it works

<?php
error_reporting(0);
$handle = fopen("file.txt", "w");


if(filter_has_var(INPUT_POST, 'tarea')){
    $_POST['tarea'] = explode("\n", $_POST['tarea']);


    for ($i=0; $i < count($_POST['tarea']) ; $i++) {
        if(!$_POST['tarea'][$i] == ""){
            $club = strrpos($_POST['tarea'][$i],"m/club");
            if( $club !== false){
                $res[] = substr($_POST['tarea'][$i],$club+6);
            } else {
                $pos = strrpos($_POST['tarea'][$i],"m/")+2;
                $res[] = substr($_POST['tarea'][$i],$pos);
            }


        }

    }


    function getSslPage($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_REFERER, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }

    function check($value, $handle) {
        fwrite($handle, "--------------------------------- ");
        $id_group = trim($value);
        $url = "http://api.vkontakte.ru/method/groups.getMembers?group_id={$id_group}&count=0&offset=0";
        $wall = json_decode(getSslPage($url),true);
        fwrite($handle, "$id_group\n");
            $count = $wall['response']['count'];
        fwrite($handle, " $count\n ");
            if($count > 1000) {

                foreach (range(0,$count, 50 ) as $number) {

                    $offset = "&offset=".$number;
                    $url = checkUrl($url = "http://api.vkontakte.ru/method/groups.getMembers?group_id={$id_group}&count=50&offset=0", $offset);
                    $wall = json_decode(getSslPage($url),true);


                    foreach ($wall['response']['users'] as $vk_ac) {


                        fwrite($handle, "{$vk_ac}\n");
                    }

                }
            }

    }

    function checkUrl($url, $offset){
        $pos = strrpos($url,"&offset=");
        $newurl = substr_replace($url,$offset,$pos);
        return $newurl;
    }

    foreach ($res as $value) {

        check($value,$handle);
    }

    fclose($handle);
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename('file.txt'));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize('file.txt'));
    readfile('file.txt');
    exit;
}


?>
<!DOCTYPE html>
<html>
<head>
    <title>Парсинг пользователей вк</title>
</head>

<body>

<form action="" method="post" >

    <textarea name="tarea" id="tarea" cols="30" rows="10"></textarea>
    <input type="submit" value="ok" >

</form>


</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
entermix, 2015-10-29
@Msim

vk.com/dev/groups.getMembers

Returns a list of community members.
This is a public method that does not require an access_token.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question