R
R
Rainbow8882020-02-06 22:41:45
PHP
Rainbow888, 2020-02-06 22:41:45

How to get a list of group members in OK via API?

Good day!

I ask for advice and I will be grateful for it. Task: get a list of group members in classmates via API. All free parsers have a limit on the number of parsed participants. It seems that there is an option to make your application OK and receive lists of group members through the API. Is it possible (preferably without deep knowledge of PHP)))?
After all, there is

5e3c6c80f2728010912667.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Abramov, 2020-02-17
@Ganzo

function arInStr($array)
{
    ksort($array);
    $string = "";
    foreach ($array as $key => $val)
    {
        if (is_array($val))
        {
            $string .= $key . "=" . arInStr($val);
        }
        else
        {
            $string .= $key . "=" . $val;
        }
    }
    return $string;
}

function postUrl($url, $type = "GET", $params = array(), $timeout = 15, $image = false, $decode = true)
{
    if ($ch = curl_init())
    {
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, false);

        if ($type == "POST")
        {
            curl_setopt($ch, CURLOPT_POST, true);


            if ($image)
            {
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            }

            elseif ($decode)
            {
                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
            }

            else
            {
                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
            }
        }

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $data = curl_exec($ch);
        curl_close($ch);

        // Еще разок, если API завис
        if (isset($data['error_code']) && $data['error_code'] == 5000)
        {
            $data = getUrl($url, $type, $params, $timeout, $image, $decode);
        }
        return $data;
    }
    else
    {
        return "{}";
    }
}

function getOk($access_token,
               $application_secret_key,
               $params,
               $timeout = 15,
               $image = false,
               $decode = true,
               $siG = true,
               $url = 'https://api.ok.ru/fb.do')
{
    if ($siG != false)
    {
        $sig = md5(arInStr($params) . md5("{$access_token}{$application_secret_key}"));
        $params["sig"] = $sig;
        $params["access_token"] = $access_token;
        $result = json_decode(postUrl("https://api.ok.ru/fb.do", "POST", $params, $timeout, $image, $decode), true);
    }
    else
    {
        $result = json_decode(postUrl($url, "POST", $params, $timeout, $image, $decode), true);
    }
    return $result;
}


$params = array(
    "application_key" => $application_key,
    "application_id" => $application_id,
    "application_secret_key" => $secret_session_key,
    "format" => "json",
    "uid" => $groupId,
    "method" => "group.getMembers",
);
$res = getOk($access_token, $application_secret_key, $params, 15, false);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question