VkInviter - an assistant assistant to VK group administrators

Good day to all!

I am the administrator of one VKontakte music group (hereinafter - VK). Musicians often go on tours to different cities of Russia and the CIS countries. One way to notify group fans of an upcoming concert in their city is to send out invitations to the appropriate VK meeting.
In the article I want to show one of the possible solutions to this problem.

I hope that this article will be useful to other group administrators, the number of user invitations to events outside their city will decrease, and more people will unlock the opportunity to invite them to meetings!


First of all, you must be the administrator of the VK group and this group must be the organizer of the meeting in VK.

The solution “Do it yourself manually”

The existing interface allows you to do this newsletter manually through the meeting menu:
“Invite friends” - “Invite group members”: The


disadvantages of this solution are obvious:
  • Long, because in some cities, the number of participants is more than a few thousand
  • It is not possible to fulfill an invitation to participants residing in a specific city


Automate Process Solution

There are two approaches: write an application using the VK API or standalone via post-get requests.

After analysis, I realized that the VK API is not suitable. There is no method for inviting a user to a meeting in the description, and I don’t really want to get involved with registering the application and other internal rules of the VK.

Therefore, you have to analyze post-get requests, and write a "simulator" of the user.

Consider the main stages of work:
  • User Authorization
  • Getting group members in a specific city
  • Distribution of invitations


Login

With login, everything is quite simple - POST request at login.vk.com:
act=login&q=1&al_frame=1&expire=1&captcha_sid=&captcha_key=&from_host=vk.com&from_protocol=http&email=USERNAME&pass=PASSWORD
In response, we get the location parameter with the address to be redirected: After the redirect, the remixsid parameter is written to the cookie - session ID, which confirms successful authorization
vk.com/login.php?act=slogin&al_frame=1&hash=bd7aed27961c325b407332b5855fa1c1&s=1




Fans from the city of N

To get a list of group members from a certain city, we will use the standard search vk.com/search, this set of filters is especially important for us: You can


search for group members from the group page, and the query will look like: where group is the group id. After adding filtering by country and city, the request will take the form: where, respectively, city is the city id, country is the country id The response to the request is a list of users. The response header contains two important values: has_more - determines whether there will still be users in the offset - “indent” or shift from the first user The block with information about one user has the form:
al_search.php?al=1&c[group]=6206&c[section]=people




al_search.php?al=1&c[city]=1&c[country]=1&c[group]=6206&c[section]=people





"has_more":true,"offset":200





Климатпрофф
Online


The data is interesting in this block:
  • id
  • name
  • href per page


Parsing an answer is quite convenient with regular expressions.
To get id, I use this expression: To get the name and href:
"]*onmouseover=\"Searcher.bigphOver\\(this, (\\d+)\\)\">"



"
([^<]+)<";


In this approach, there is one synthetic limitation - the contact does not produce more than 1000 search results. This is critical, because, for example, in Moscow, a group of 3000+ participants. To get around this restriction, you will have to add additional filtering to users, and then combine the results of all filters.

From the available ones, only those filters should be selected for which the values ​​are fixed and there are not so many. Suitable
for this task:
Gender - [sex], values: 0-2
Sort order - [sortId], values ​​0-1
Marital status - [statusId], values ​​0-7.

On ruby, this enumeration looks like this:
offset=0
	for sort_id in 0..1 do
		for status_id in 0..7 do
			for sex_id in 0..2 do
				offset=0
				begin
					get_str = "/al_search.php?al=1"
					get_str += "&c[city]=#{city_id}" if city_id.to_i>0
					get_str += "&c[country]=#{country_id}" if country_id.to_i>0
					get_str += "&c[group]=#{group_id}"
					get_str += "&c[name]=1&c[section]=people"
					get_str += "&c[sex]=#{sex_id}" if sex_id>0
					get_str += "&c[sort]=#{sort_id}" if sort_id>0
					get_str += "&c[status]=#{status_id}" if status_id>0
					get_str += "&offset=#{offset}" if offset>0
					...


Thus, a list of all users in the city will be obtained.

If we will send invitations manually, we will notice that it is sent using the POST method: where gid is the meeting id, mid is the user id, hash is a hash that carries information about the inviter. This hash now needs to be obtained for all users from our list.
act=a_invite&al=1&gid=65898108&hash=99247d766b77d7a584&mid=22935



Getting hash

To get the hash, you have to parse the list of “friends” whom I can invite to the meeting. Friends are shown in quotation marks, as here, under this concept, all participants of the organizing group are speaking.

The GET request to get this list looks like this: where gid is the meeting id The answer is a json string with a set of blocks of the form: where the 1st parameter is the user id and the last is the hash we need. Processing of this data was performed using a regular expression: The format of this answer changes quite often, so the trick was done in the program: additionally, the number of links to avatars is calculated (2-parameter) and the number of avatars and users matches after processing. In C #, this check looks like this:
vk.com/friends?act=get_section_friends&al=1&gid=65898108&offset=0§ion=members&sugg_rev=0



['1298','http://cs315422.vk.me/u01298/d_e13351b2.jpg','/id1298','2','0','Сергей Суворов','0','1','61','','0','2d9d4211c2297c3a06']



@"\['(\d*)','[^']*','\/([\w\.]+)','[^']*','[^']*','([^']+)','[^']*','(\d+)','[^']*','[^']*','[^']*','(\w+)'\]"





string patternNorm = @"'http:\/\/cs\d+\.vk\.me";
string patternDeactiveOrDeleted = @"'\/images\/\w+\.gif'";
MatchCollection mcNorm = Regex.Matches(responseString, patternNorm);
MatchCollection mcDeactiveOrDeleted = Regex.Matches(responseString, patternDeactiveOrDeleted);
int httpCount = mcNorm.Count + mcDeactiveOrDeleted.Count;
if (listVkUser.Count != httpCount)
{
	throw new Exception("http total count != user count");
}


After processing the list of “friends” and merging it with the list of users from the city, everything is ready for sending invitations.

During the distribution process, it was found out that after every 40 invitations it is necessary to enter captcha, a link to the captcha is issued in the form:, where sid is the unique id of this captcha. With each request for this url, a new picture with a captcha will be issued. Here is the only place where user participation and manual input are required in the process.
captcha.php?sid={1}&s=1




VkInviter Program

To automate these actions, VkInviter is written.
The main window of the program is shown in the screenshot:
image
In addition to the described algorithm, the program allows you to select several cities, which is important when invitations are sent not only to the city, but also to the nearest areas.

The source code is uploaded to
github , a ruby script has also been uploaded , which can be useful for understanding the general logic.

Conclusion

In conclusion, I want to say a few words about efficiency.
Noticed that approximately 60% of all users were forbidden to invite themselves to meetings.
Of those who accept an invitation to a meeting, somewhere around 10% come.
I don’t know how long this functionality will remain in VK and why the opportunity to invite everyone was drunk several years ago.

Anyone can use the source code at their discretion.

Also popular now: