vkfeed

 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
#include <string>
#include <iostream>
#include <curl/curl.h>
#include "include/rapidjson/document.h"
#include "include/rapidjson/writer.h"
#include "include/rapidjson/stringbuffer.h"
using namespace rapidjson;
static std::string buffer;
static int writer(char* data, size_t size, size_t nmemb, std::string* buffer) {
int result = 0;
if (buffer != NULL)
{
buffer->append(data, size* nmemb);
result = size* nmemb;
}
return result;
}
static std::string vk(std::string method, std::string data, std::string token = "e5eadb782bd8huivamanetokende3e33a31ee7e2fe6e93378a72124e7ec3690a81352f82233a81f0") {
CURL* curl;
CURLcode result;
std::string url = "https://api.vk.com/method/"+method;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
result = curl_easy_perform(curl);
}
return buffer;
}
int main(int argc, char* argv[]) {
std::string ss = vk("users.get", "user_ids=cubexx&fields=city");
const char* json = ss.c_str();
Document d;
d.Parse(json);
Value& s = d["response"];
Value& sa = s["uid"];
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
d.Accept(writer);
std::cout << buffer.GetString();
return 0;
}