Created
May 23, 2019 21:45
-
-
Save sayurin/8f906db62087a1e2139e109872d95e66 to your computer and use it in GitHub Desktop.
Sample Twitter client using C++ REST SDK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <locale> | |
#include <cpprest/http_client.h> | |
#include <cpprest/oauth1.h> | |
static constexpr auto | |
apikey = U(""), | |
apisecretkey = U(""), | |
accesstoken = U(""), | |
accesstokensecret = U(""); | |
int wmain() { | |
// コンソールに日本語を表示するための設定 | |
_wsetlocale(LC_ALL, L""); | |
web::http::oauth1::experimental::oauth1_config oauth1_config{ | |
apikey, | |
apisecretkey, | |
U("https://api.twitter.com/oauth/request_token"), | |
U("https://api.twitter.com/oauth/authorize"), | |
U("https://api.twitter.com/oauth/access_token"), | |
U(""), | |
web::http::oauth1::experimental::oauth1_methods::hmac_sha1 | |
}; | |
oauth1_config.set_token({ accesstoken, accesstokensecret }); | |
web::http::client::http_client_config http_client_config; | |
http_client_config.set_oauth1(oauth1_config); | |
web::http::client::http_client api{ U("https://api.twitter.com/1.1/"), http_client_config }; | |
auto timeline = api.request(web::http::methods::GET, U("statuses/home_timeline.json")).get().extract_json().get(); | |
for (auto const& status : timeline.as_array()) | |
ucout << status.as_object().at(U("text")).as_string() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment