2018-03-13 13:25:01 +01:00
|
|
|
/* This file is part of mastodon-cpp.
|
|
|
|
* Post the same media 2 times, with URLs
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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-03-13 13:25:01 +01:00
|
|
|
|
|
|
|
using Mastodon::API;
|
|
|
|
|
|
|
|
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-03-18 14:53:51 +01:00
|
|
|
Json::Value json;
|
2018-03-13 13:25:01 +01:00
|
|
|
std::uint16_t ret;
|
|
|
|
std::string filepath;
|
|
|
|
|
|
|
|
std::cout << "Absolute filename: ";
|
|
|
|
std::cin >> filepath;
|
|
|
|
|
|
|
|
API::parametermap parameters =
|
|
|
|
{
|
|
|
|
{ "file", { filepath } }
|
|
|
|
};
|
|
|
|
ret = masto.post(API::v1::media, parameters, answer);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
2018-03-18 17:34:44 +01:00
|
|
|
ss.str(answer);
|
|
|
|
ss >> json;
|
2018-03-18 14:53:51 +01:00
|
|
|
std::string image1_id = json["id"].asString();
|
|
|
|
std::string image1_url = json["url"].asString();
|
2018-03-13 13:25:01 +01:00
|
|
|
parameters =
|
|
|
|
{
|
|
|
|
{ "file", { filepath } }
|
|
|
|
};
|
|
|
|
ret = masto.post(API::v1::media, parameters, answer);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
2018-03-18 17:34:44 +01:00
|
|
|
ss.str(answer);
|
|
|
|
ss >> json;
|
2018-03-18 14:53:51 +01:00
|
|
|
std::string image2_id = json["id"].asString();
|
|
|
|
std::string image2_url = json["url"].asString();
|
2018-03-13 13:25:01 +01:00
|
|
|
parameters =
|
|
|
|
{
|
|
|
|
{ "status", { image1_url + " \n" + image2_url } },
|
|
|
|
{ "media_ids", { image1_id, image2_id } },
|
|
|
|
{ "visibility", { "direct" } }
|
|
|
|
};
|
|
|
|
ret = masto.post(API::v1::statuses, parameters, answer);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ret == 13)
|
|
|
|
{
|
|
|
|
std::cerr << "The URL has permanently changed.\n" <<
|
|
|
|
"New URL: " << answer << '\n';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << answer << '\n';
|
|
|
|
std::cerr << "Error code: " << ret << '\n';
|
|
|
|
return ret;
|
|
|
|
}
|