A
A
ArbuzzzzZ2013-09-28 19:45:55
Social media
ArbuzzzzZ, 2013-09-28 19:45:55

How to count the number of likes for a comment from group members (VK)?

There are applications and services for checking “cheated” likes, but they work with posts or photos. What to do in this situation? I understand that this is possible using the VK API, but my level in this is slightly less than 0.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ArbuzzzzZ, 2013-09-30
@ArbuzzzzZ

So here's my solution. Clumsy, but works.
1. vk.com/dev/execute Enter
the code:
var group_id = <group id>;
var users = [];
var count = API.groups.getMembers({group_id: group_id}).count;
var offset = 0;
while (offset < count && offset <= 23000) {
users = users + API.groups.getMembers({group_id: group_id, offset: offset, count: 1000}).users;
offset = offset + 1000;
}
return users;
We save the resulting array in txt, carefully replacing all commas with nothing through Ctrl + H, so that it would be easier to feed the future program.
2. vk.com/dev.php?method=likes.getList
Here we get an array of id of users who have rated the post and write it to a new txt.
3. My clumsy code of the program that outputs the common elements of these arrays to a new file.
#include #include #include <assert.h>
using namespace std;
int main()
{
//
int a[10000];
int i=0;
intj=0;
int s=0;
intb[200];
ifstream in;
outstream out;
in.open("input_1.txt");
while (!in.eof()) {
i++;
in>>a[i];
}
in.close();
i=0;
in.open("input_2.txt");
while (!in.eof()) {
i++;
in>>b[i];
}
in.close();
out.open("output_1.txt");
for (i=0;i<9380;++i)
{
for (j=0;j<171;++j)
{
if (a[i]==b[j])
{
out<<a[i ]<<", ";
cout<<j<<endl;
s++;
};
};
};
out<<endl<<"Total: „<<s;
out.close();
cin.get();
//
return 0;
}
Parameters a,b and loop conditions change depending on the conditions :)
I did everything right in the debugger, so everything changes right in the code.
Next, we clean output_1 from zeros that may have appeared there (so Total is not telling the truth), we leave the commas, because we will then feed it to VK ...
4. vk.com/dev/users.
We feed here the list of id received in the third paragraph. At the output, we get a list of id already with first and last names (if fields are left empty).
5. Well, we drive this list into txt and already through Ctrl + H we can bring it into a more or less adequate form.
Well, that's all. I'm sure someone can do much better, but this option coped with the task.

V
Vladimir, 2013-09-29
@br3t

We look at the documentation: https://vk.com/dev/likes.getList
For example, we need to get the number of likes of Alexander Pershin's comment to the post https://vk.com/webfont?w=wall-45971686_240
In the "Like" button code we find
<span class="like_link fl_l" id="like_link-45971686_wall_reply243" style="opacity: 1;">Мне нравится</span>
The first number in id is owner_id, the second is item_id
Substituting the value in the constructor from the dev page, we get the request:
https://api.vkontakte.ru/method/likes.getList?type=comment&owner_id=-45971686&item_id=243
and we get in answer:
{"response":{"count":2,"users":[53901371,8324281]}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question