C++ wrapper for the Mastodon API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example17_bookmarks.cpp 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* This file is part of mastodon-cpp.
  2. * Print the first 20 characters from every bookmark (Glitch-Soc only).
  3. */
  4. // Don't compile this if the Easy-interface is turned off
  5. #ifndef WITHOUT_EASY
  6. #include <iostream>
  7. #include <vector>
  8. #include <string>
  9. #include <cstdint>
  10. #ifdef MASTODON_CPP
  11. #include "mastodon-cpp.hpp"
  12. #include "easy/all.hpp"
  13. #else
  14. #include <mastodon-cpp/mastodon-cpp.hpp>
  15. #include <mastodon-cpp/easy/all.hpp>
  16. #endif
  17. using std::cout;
  18. using Mastodon::API;
  19. using Mastodon::Easy;
  20. int main(int argc, char *argv[])
  21. {
  22. if (argc < 3)
  23. {
  24. std::cerr << "usage: " << argv[0] << " <instance> <access token>\n";
  25. return 1;
  26. }
  27. Easy masto(argv[1], argv[2]);
  28. std::string answer;
  29. std::uint16_t ret;
  30. ret = masto.get(API::v1::bookmarks, answer);
  31. cout << "Return code: " << ret << '\n';
  32. std::vector<string> statuses = Easy::json_array_to_vector(answer);
  33. for (const string &json : statuses)
  34. {
  35. cout << Easy::Status(json).content().substr(0, 20) << '\n';
  36. }
  37. return 0;
  38. }
  39. #else
  40. #include <cstdio>
  41. int main()
  42. {
  43. printf("mastodon-cpp was compiled without Easy support.\n");
  44. return 255;
  45. }
  46. #endif // WITHOUT_EASY