Updated examples to work well with newer jsoncpp versions
This commit is contained in:
parent
4f97ef5a37
commit
c01af9a197
|
@ -6,6 +6,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include "../mastodon-cpp.hpp"
|
||||
|
||||
|
@ -22,14 +23,15 @@ int main(int argc, char *argv[])
|
|||
|
||||
Mastodon::API masto(argv[1], argv[2]);
|
||||
std::string answer;
|
||||
std::stringstream ss;
|
||||
std::uint16_t ret;
|
||||
|
||||
ret = masto.get(API::v1::accounts_verify_credentials, answer);
|
||||
if (ret == 0)
|
||||
{
|
||||
Json::Reader reader;
|
||||
ss.str(answer);
|
||||
Json::Value json;
|
||||
reader.parse(answer, json);
|
||||
ss >> json;
|
||||
|
||||
std::string uid = json["id"].asString();
|
||||
cout << "Your ID is: " << uid << '\n';
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <regex>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include "../mastodon-cpp.hpp"
|
||||
|
||||
|
@ -33,6 +34,7 @@ int main(int argc, char *argv[])
|
|||
Mastodon::API masto(argv[1], "");
|
||||
string hashtag = argv[2];
|
||||
string answer;
|
||||
std::stringstream ss;
|
||||
std::uint16_t ret;
|
||||
Json::Value config;
|
||||
string lastid = "0";
|
||||
|
@ -40,7 +42,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
// Read config file, get last seen toot-id
|
||||
try {
|
||||
Json::Reader reader;
|
||||
std::ifstream file(filename, std::ifstream::binary);
|
||||
file >> config;
|
||||
lastid = config.get(hashtag, "0").asString();
|
||||
|
@ -74,9 +75,9 @@ int main(int argc, char *argv[])
|
|||
cout << ornament << '\n';
|
||||
|
||||
Json::Value tree;
|
||||
Json::Reader reader;
|
||||
ss.str(answer);
|
||||
ss >> tree;
|
||||
|
||||
reader.parse(answer, tree);
|
||||
for (const auto &toot : tree)
|
||||
{
|
||||
string content = toot["content"].asString();
|
||||
|
@ -102,8 +103,8 @@ int main(int argc, char *argv[])
|
|||
lastid = tree[0]["id"].asString();
|
||||
config[hashtag] = lastid;
|
||||
|
||||
Json::StyledWriter writer;
|
||||
const string output = writer.write(config);
|
||||
Json::StreamWriterBuilder wbuilder;
|
||||
const string output = Json::writeString(wbuilder, config);
|
||||
std::ofstream outfile(filename);
|
||||
if (outfile.is_open())
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include "../mastodon-cpp.hpp"
|
||||
|
||||
|
@ -21,8 +22,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
Mastodon::API masto(argv[1], argv[2]);
|
||||
std::string answer;
|
||||
std::stringstream ss;
|
||||
Json::Value json;
|
||||
Json::Reader reader;
|
||||
std::uint16_t ret;
|
||||
std::string filepath;
|
||||
|
||||
|
@ -36,7 +37,8 @@ int main(int argc, char *argv[])
|
|||
ret = masto.post(API::v1::media, parameters, answer);
|
||||
if (ret == 0)
|
||||
{
|
||||
reader.parse(answer, json);
|
||||
ss.str(answer);
|
||||
ss >> json;
|
||||
std::string image1_id = json["id"].asString();
|
||||
std::string image1_url = json["url"].asString();
|
||||
parameters =
|
||||
|
@ -46,7 +48,8 @@ int main(int argc, char *argv[])
|
|||
ret = masto.post(API::v1::media, parameters, answer);
|
||||
if (ret == 0)
|
||||
{
|
||||
reader.parse(answer, json);
|
||||
ss.str(answer);
|
||||
ss >> json;
|
||||
std::string image2_id = json["id"].asString();
|
||||
std::string image2_url = json["url"].asString();
|
||||
parameters =
|
||||
|
|
Reference in New Issue
Block a user