2018-01-06 21:33:52 +01:00
|
|
|
/* This file is part of mastodon-cpp.
|
2018-01-15 00:08:14 +01:00
|
|
|
* This example dumps the raw JSON of your last toot with media attached
|
|
|
|
* and your last 2 followers.
|
2018-01-06 21:33:52 +01:00
|
|
|
*/
|
|
|
|
|
2018-01-09 22:12:11 +01:00
|
|
|
#include <iostream>
|
2018-01-13 00:34:16 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2018-01-13 15:49:46 +01:00
|
|
|
#include <cstdint>
|
2018-01-06 21:33:52 +01:00
|
|
|
#include "../mastodon-cpp.hpp"
|
|
|
|
|
2018-01-12 20:49:15 +01:00
|
|
|
using Mastodon::API;
|
|
|
|
|
2018-01-06 21:33:52 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2018-01-09 22:12:11 +01:00
|
|
|
if (argc < 3)
|
|
|
|
{
|
|
|
|
std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mastodon::API masto(argv[1], argv[2]);
|
2018-01-13 16:48:52 +01:00
|
|
|
masto.set_useragent("mastodon-cpp-example/1.3.3.7");
|
2018-01-13 15:49:46 +01:00
|
|
|
std::string answer;
|
|
|
|
std::uint16_t ret;
|
2018-01-09 22:12:11 +01:00
|
|
|
|
2018-01-13 15:49:46 +01:00
|
|
|
ret = masto.get(API::v1::accounts_verify_credentials, answer);
|
|
|
|
if (ret == 0)
|
2018-01-13 00:34:16 +01:00
|
|
|
{
|
2018-01-13 15:49:46 +01:00
|
|
|
std::cout << "Your last toot with media attached:\n";
|
|
|
|
std::string uid = answer.substr(7, answer.find("\"", 7) - 7);
|
2018-01-15 20:23:21 +01:00
|
|
|
API::parametermap parameters =
|
2018-01-13 15:49:46 +01:00
|
|
|
{
|
2018-01-15 20:23:21 +01:00
|
|
|
{ "limit", { "1" } },
|
|
|
|
{ "only_media", { "1" } }
|
2018-01-13 15:49:46 +01:00
|
|
|
};
|
|
|
|
|
2018-01-13 16:07:00 +01:00
|
|
|
ret = masto.get(API::v1::accounts_id_statuses, uid,parameters, answer);
|
2018-01-13 15:49:46 +01:00
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
std::cout << answer << '\n';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Error code: " << ret << '\n';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "\nYour last 2 followers:\n";
|
|
|
|
parameters =
|
|
|
|
{
|
2018-01-15 20:23:21 +01:00
|
|
|
{
|
|
|
|
"limit", { "2" }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"exclude_types", { "favourite", "reblog", "mention" }
|
|
|
|
}
|
2018-01-13 15:49:46 +01:00
|
|
|
};
|
|
|
|
ret = masto.get(API::v1::notifications, parameters, answer);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
std::cout << answer << '\n';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Error code: " << ret << '\n';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
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-13 16:07:00 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Error code: " << ret << '\n';
|
|
|
|
return ret;
|
|
|
|
}
|
2018-01-13 15:49:46 +01:00
|
|
|
|
|
|
|
return 0;
|
2018-01-06 21:33:52 +01:00
|
|
|
}
|