2018-01-15 00:08:14 +01:00
|
|
|
/* This file is part of mastodon-cpp.
|
|
|
|
* This example parses your account data and prints it out in a readable way.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <cstdint>
|
2018-03-18 17:34:44 +01:00
|
|
|
#include <sstream>
|
2018-03-18 14:53:51 +01:00
|
|
|
#include <jsoncpp/json/json.h>
|
2018-03-21 20:12:45 +01:00
|
|
|
#ifdef MASTODON_CPP
|
|
|
|
#include "mastodon-cpp.hpp"
|
|
|
|
#else
|
|
|
|
#include <mastodon-cpp/mastodon-cpp.hpp>
|
|
|
|
#endif
|
2018-01-15 00:08:14 +01:00
|
|
|
|
|
|
|
using Mastodon::API;
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc < 3)
|
|
|
|
{
|
|
|
|
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mastodon::API masto(argv[1], argv[2]);
|
|
|
|
std::string answer;
|
2018-03-18 17:34:44 +01:00
|
|
|
std::stringstream ss;
|
2018-01-15 00:08:14 +01:00
|
|
|
std::uint16_t ret;
|
|
|
|
|
|
|
|
ret = masto.get(API::v1::accounts_verify_credentials, answer);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
2018-03-18 17:34:44 +01:00
|
|
|
ss.str(answer);
|
2018-03-18 14:53:51 +01:00
|
|
|
Json::Value json;
|
2018-03-18 17:34:44 +01:00
|
|
|
ss >> json;
|
2018-03-18 14:53:51 +01:00
|
|
|
|
|
|
|
std::string uid = json["id"].asString();
|
2018-01-15 00:08:14 +01:00
|
|
|
cout << "Your ID is: " << uid << '\n';
|
|
|
|
cout << "Your whole acount tree:\n";
|
|
|
|
|
2018-03-18 14:53:51 +01:00
|
|
|
for (auto it = json.begin(); it != json.end(); ++it)
|
2018-01-15 00:08:14 +01:00
|
|
|
{
|
2018-03-18 14:53:51 +01:00
|
|
|
if (it.name().compare("source") == 0)
|
2018-01-15 00:08:14 +01:00
|
|
|
{
|
2018-03-18 14:53:51 +01:00
|
|
|
cout << it.name() << '\n';
|
|
|
|
for (auto it_s = (*it).begin(); it_s != (*it).end(); ++it_s)
|
2018-01-15 00:08:14 +01:00
|
|
|
{
|
2018-03-18 14:53:51 +01:00
|
|
|
cout << '\t' << it_s.name() << ": ";
|
|
|
|
cout << *it_s << '\n';
|
2018-01-15 00:08:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-18 14:53:51 +01:00
|
|
|
cout << it.name() << ": ";
|
|
|
|
cout << *it << '\n';
|
2018-01-15 00:08:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-28 22:37:30 +01:00
|
|
|
else if (ret == 13)
|
2018-02-17 20:01:51 +01:00
|
|
|
{
|
|
|
|
std::cerr << "The URL has permanently changed.\n" <<
|
|
|
|
"New URL: " << answer << '\n';
|
|
|
|
return ret;
|
|
|
|
}
|
2018-01-15 00:08:14 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Error code: " << ret << '\n';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|