-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.cpp
executable file
·70 lines (58 loc) · 1.58 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include "src/api.h"
using namespace std;
string fa2_callback() {
string res;
cout << "Enter 2fa code: ";
cin >> res;
return res;
}
string captcha_callback(const string &captcha_sid) {
string res;
cout << "Open image https://api.vk.com/captcha.php?sid=" << captcha_sid;
cout << " and enter text: " << endl;
cin >> res;
return res;
}
void print_man() {
cout << "Usage: [access_token] login pass" << endl;
}
int main(int argc, char *argv[]) {
if(argc < 2 || argc > 4) {
print_man();
return 1;
}
string access_token, login, pass;
if(argc == 2) {
access_token = argv[1];
} else if(argc == 3) {
login = argv[1];
pass = argv[2];
} else if(argc == 4) {
access_token = argv[1];
login = argv[2];
pass = argv[3];
} else {
print_man();
return 1;
}
VK::Client api;
api.set_fa2_callback(fa2_callback);
api.set_cap_callback(captcha_callback);
if(api.auth(login, pass, access_token)) {
cout << "Auth ok" << endl;
cout << "Access token: " << api.access_token() << endl;
VK::params_map params = {
{"owner_id", "134575353"},
{"message", "Hello from VK API"}
};
cout << "API response: " << endl;
cout << api.call("wall.post", params) << endl;
/* alternative method
api.call("wall.post", "owner_id=134575353&message=Hello from VK API");
*/
} else {
cout << "Auth fail: " << api.last_error() << endl;
}
return 0;
}