Skip to content

Instantly share code, notes, and snippets.

@sayurin
Created May 23, 2019 21:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayurin/8f906db62087a1e2139e109872d95e66 to your computer and use it in GitHub Desktop.
Save sayurin/8f906db62087a1e2139e109872d95e66 to your computer and use it in GitHub Desktop.
Sample Twitter client using C++ REST SDK.
#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