diff --git a/README.md b/README.md index b5d9ddf..7106e74 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,16 @@ CocoaTweet::API::API api(key); ``` +### NOTE +if you want to call Twitter API using Bearer Token; OAuth2, you can do. +``` +api.generateBearerToken(); +``` +After call it, always use Bearer Token to access API which kinds of GET method. +no affect to POST method. +then, if you use this, and ONLY use kind of GET API, you DO NOT need acess token. + + ## Use API ``` // Post a tweet diff --git a/api_key.json b/api_key.json index 33be5e1..37865c0 100644 --- a/api_key.json +++ b/api_key.json @@ -1,6 +1,6 @@ { - "consumer_key" : "ZppPUpvBAdG5pG1dXpmunKAWs", - "consumer_secret" : "eb8kIaw5xNFCjDkgATk3TmsehOnHhsNW1TCiOM2BK1zM0eOFrR", - "access_token" : "2224351076-elEMPKpQEwTRL9wphhqteU8zbjdMMqyMjkmRA2o", - "access_token_secret" : "0HiqIMPZwHwoM5cpawvNv5YSKYwEIYt7NXyeIoNfLqOMS" + "consumer_key" : "HmXS3q4yrQ2wndiCQzH8YnUQM", + "consumer_secret" : "qZwdGJYGFMpz7CSVGPHmbrh0O3Sk99wa0OLMf8HSvKKtNclrnf", + "access_token" : "1427931990792146949-iuNX8xBgQSXGtxr5cz8m495OtnXKcw", + "access_token_secret" : "A0R7vOOR3pRm4trGLxVbwNiQTkOMAkEh3z5ed3IxJVbJl" } diff --git a/src/cocoatweet/api/interface/httpGet.cc b/src/cocoatweet/api/interface/httpGet.cc index 663fd41..9699e2c 100644 --- a/src/cocoatweet/api/interface/httpGet.cc +++ b/src/cocoatweet/api/interface/httpGet.cc @@ -103,8 +103,9 @@ void HttpGet::process(std::weak_ptr _oauth, throw std::runtime_error(std::string("INTERNAL ERROR : curl(") + std::to_string(res) + ")"); exit(1); } - +#ifndef NDEBUG std::cout << rcv << std::endl; +#endif if ((responseCode / 100) == 4) { auto j = nlohmann::json::parse(rcv); auto error = j["errors"][0]["code"]; diff --git a/src/cocoatweet/api/interface/httpPost.cc b/src/cocoatweet/api/interface/httpPost.cc index 10d4215..e318245 100644 --- a/src/cocoatweet/api/interface/httpPost.cc +++ b/src/cocoatweet/api/interface/httpPost.cc @@ -114,6 +114,9 @@ void HttpPost::process(std::weak_ptr _oauth, exit(1); } +#ifndef NDEBUG + std::cout << rcv << std::endl; +#endif if ((responseCode / 100) == 4) { auto j = nlohmann::json::parse(rcv); auto error = j["errors"][0]["code"]; diff --git a/src/main.cc b/src/main.cc index 8487682..fdc0563 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,21 +1,6 @@ -#include "cocoatweet/oauth/key.h" -#include "cocoatweet/api/api.h" -#include - +#include #include -#include -#include -#include -#include - #include -#include - -bool starts_with(const std::string& s, const std::string& prefix) { - auto size = prefix.size(); - if (s.size() < size) return false; - return std::equal(std::begin(prefix), std::end(prefix), std::begin(s)); -} auto main() -> int { // Generate Key object @@ -36,12 +21,16 @@ auto main() -> int { // if you want to access api using Bearer Token, call this for get BearerToken; // NOTE: call this, always authenticate with Bearer Token, which is Read Only Token - // api.generateBearerToken(); + // try { + // api.generateBearerToken(); - // Now, you can use a twitter api - // auto status = api.status().update("Hello Twitter World via Cocoa Twitter Library"); - // api.favorite().create(status.id()); - // api.favorite().destroy(status.id()); - // api.status().destroy(status.id()); - // auto timeline = api.status().userTimeline("milkcocoa0902"); + // Now, you can use a twitter api + // auto status = api.status().update("Hello Twitter World via Cocoa Twitter Library"); + // api.favorite().create(status.id()); + // api.favorite().destroy(status.id()); + // api.status().destroy(status.id()); + // auto timeline = api.status().userTimeline("milkcocoa0902"); + // } catch (CocoaTweet::Exception::Exception e) { + // std::cout << e.what() << std::endl; + // } }