N
N
nastyskafomka2018-08-29 02:17:35
API
nastyskafomka, 2018-08-29 02:17:35

How to check if a person is in a group?

Is it necessary to have an application to check if a person is a subscriber of the group where the bot works?
If not, how can this be implemented? (You will need to display a message if the person is not subscribed.

spoiler
switch ($data->type){

    case 'confirmation':
        echo $confirmation_token;
        break;
    case 'message_new':
        $user_id = $data->object->user_id;
        $sostoit = file_get_contents('https://api.vk.com/method/groups.isMember?group_id='. $group_id .'&user_id='. $user_id .'extended=1');
        $member = json_decode($sostoit, true);
        if ($member['response']['member']==0){
          $request_params = [
            'message' => "Сначала в группу вступи!",
            'user_id' => $user_id,
            'access_token' => $token,
            'v' => $api_version
          ];
          $get_params = http_build_query($request_params);
          file_get_contents('https://api.vk.com/method/'. $msg_send . $get_params);
          echo('ok');
          break;
        }
          else { 
                          Тут остальной код, если человек состоит в группе
}

In unsuccessful requests writes
Error: HTTP response code said error. Attempt 1/5
Error: HTTP response code said error. Attempt 2/5

Okay with the first mistake, but with the second. Is it necessary to have an application? And how in general to connect it to the bot and take data from there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nastyskafomka, 2018-08-29
@nastyskafomka

Issue resolved.
The group membership check request should look like this:
https://api.vk.com/method/groups.isMember?group_id= ".$group_id ."&user_id=".$user_id."&extended=1&access_token=".$token ."&v=".$api_version);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question