README
This commit is contained in:
@@ -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
|
## Use API
|
||||||
```
|
```
|
||||||
// Post a tweet
|
// Post a tweet
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"consumer_key" : "ZppPUpvBAdG5pG1dXpmunKAWs",
|
"consumer_key" : "HmXS3q4yrQ2wndiCQzH8YnUQM",
|
||||||
"consumer_secret" : "eb8kIaw5xNFCjDkgATk3TmsehOnHhsNW1TCiOM2BK1zM0eOFrR",
|
"consumer_secret" : "qZwdGJYGFMpz7CSVGPHmbrh0O3Sk99wa0OLMf8HSvKKtNclrnf",
|
||||||
"access_token" : "2224351076-elEMPKpQEwTRL9wphhqteU8zbjdMMqyMjkmRA2o",
|
"access_token" : "1427931990792146949-iuNX8xBgQSXGtxr5cz8m495OtnXKcw",
|
||||||
"access_token_secret" : "0HiqIMPZwHwoM5cpawvNv5YSKYwEIYt7NXyeIoNfLqOMS"
|
"access_token_secret" : "A0R7vOOR3pRm4trGLxVbwNiQTkOMAkEh3z5ed3IxJVbJl"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,8 +103,9 @@ void HttpGet::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
throw std::runtime_error(std::string("INTERNAL ERROR : curl(") + std::to_string(res) + ")");
|
throw std::runtime_error(std::string("INTERNAL ERROR : curl(") + std::to_string(res) + ")");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
std::cout << rcv << std::endl;
|
std::cout << rcv << std::endl;
|
||||||
|
#endif
|
||||||
if ((responseCode / 100) == 4) {
|
if ((responseCode / 100) == 4) {
|
||||||
auto j = nlohmann::json::parse(rcv);
|
auto j = nlohmann::json::parse(rcv);
|
||||||
auto error = j["errors"][0]["code"];
|
auto error = j["errors"][0]["code"];
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
std::cout << rcv << std::endl;
|
||||||
|
#endif
|
||||||
if ((responseCode / 100) == 4) {
|
if ((responseCode / 100) == 4) {
|
||||||
auto j = nlohmann::json::parse(rcv);
|
auto j = nlohmann::json::parse(rcv);
|
||||||
auto error = j["errors"][0]["code"];
|
auto error = j["errors"][0]["code"];
|
||||||
|
|||||||
+5
-16
@@ -1,21 +1,6 @@
|
|||||||
#include "cocoatweet/oauth/key.h"
|
#include <cocoatweet/api/api.h>
|
||||||
#include "cocoatweet/api/api.h"
|
|
||||||
#include <cocoatweet/api/directMessage/new.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#include <cocoatweet/exception/exception.h>
|
#include <cocoatweet/exception/exception.h>
|
||||||
#include <cocoatweet/exception/rateLimitException.h>
|
|
||||||
|
|
||||||
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 {
|
auto main() -> int {
|
||||||
// Generate Key object
|
// Generate Key object
|
||||||
@@ -36,6 +21,7 @@ auto main() -> int {
|
|||||||
|
|
||||||
// if you want to access api using Bearer Token, call this for get BearerToken;
|
// 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
|
// NOTE: call this, always authenticate with Bearer Token, which is Read Only Token
|
||||||
|
// try {
|
||||||
// api.generateBearerToken();
|
// api.generateBearerToken();
|
||||||
|
|
||||||
// Now, you can use a twitter api
|
// Now, you can use a twitter api
|
||||||
@@ -44,4 +30,7 @@ auto main() -> int {
|
|||||||
// api.favorite().destroy(status.id());
|
// api.favorite().destroy(status.id());
|
||||||
// api.status().destroy(status.id());
|
// api.status().destroy(status.id());
|
||||||
// auto timeline = api.status().userTimeline("milkcocoa0902");
|
// auto timeline = api.status().userTimeline("milkcocoa0902");
|
||||||
|
// } catch (CocoaTweet::Exception::Exception e) {
|
||||||
|
// std::cout << e.what() << std::endl;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user