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