access tokenが取得できるように

This commit is contained in:
keita
2022-04-23 04:55:43 +09:00
parent d43e04506b
commit 560fe707a6
75 changed files with 591 additions and 193 deletions
+35
View File
@@ -0,0 +1,35 @@
#include "cocoatweet/authentication/key.h"
#include "nlohmann/json.hpp"
#include <fstream>
#include <string>
#include <typeinfo>
namespace CocoaTweet::Authentication {
Key Key::fromJsonFile(const std::string _jsonFile) {
std::ifstream ifs(_jsonFile);
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
auto j = nlohmann::json::parse(str);
Key key;
key.authType(Key::AUTH_TYPE::OAUTH10A);
if (j.contains("consumer_key")) {
key.consumerKey(j["consumer_key"].get<std::string>());
}
if (j.contains("consumer_secret")) {
key.consumerSecret(j["consumer_secret"].get<std::string>());
}
if (j.contains("access_token")) {
key.accessToken(j["access_token"].get<std::string>());
}
if (j.contains("access_token_secret")) {
key.accessTokenSecret(j["access_token_secret"].get<std::string>());
}
return key;
}
} // namespace CocoaTweet::Authentication