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.

example16_account_fields.cpp 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* This file is part of mastodon-cpp.
  2. * Get fields from own account.
  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::accounts_verify_credentials, answer);
  31. cout << "Return code: " << ret << '\n';
  32. Easy::Account account(answer);
  33. std::vector<Easy::Account::fields_pair> fields(account.fields());
  34. for (const auto &field : fields)
  35. {
  36. cout << "Name: " << field.first << "\nValue: " << field.second << "\n\n";
  37. }
  38. return 0;
  39. }
  40. #else
  41. #include <cstdio>
  42. int main()
  43. {
  44. printf("mastodon-cpp was compiled without Easy support.\n");
  45. return 255;
  46. }
  47. #endif // WITHOUT_EASY