109 lines
2.4 KiB
Markdown
109 lines
2.4 KiB
Markdown

|
|

|
|

|
|

|
|
|
|
# CocoaTweet
|
|
This is a library for using Twitter API from C++
|
|
|
|
# Dependency
|
|
- libcurl(openssl version)
|
|
- libssl
|
|
|
|
# Instllation
|
|
## Ubuntu
|
|
```
|
|
# apt install clang cmake git libboost-dev libboost-test-dev libcurl4-openssl-dev libssl-dev nunja-build
|
|
$ git clone https://github.com/koron0902/CocoaTweet
|
|
$ cd CocoaTweet // HINT : see bellow for more build faster
|
|
$ mkdir build
|
|
$ cd build
|
|
$ cmake .. -G Ninja
|
|
$ ninja
|
|
```
|
|
|
|
## Windows
|
|
T.B.D.
|
|
|
|
## HINT
|
|
in the default, test code also linked when build.
|
|
you can build more faster modifing CMakeLists.txt
|
|
```
|
|
$ vi CMakeLists.txt (or other editor you like)
|
|
|
|
// line 73
|
|
# enable_testing()
|
|
|
|
// line 76
|
|
# add_subdirectory(test)
|
|
|
|
```
|
|
|
|
# Features
|
|
you can use these endpoint
|
|
- statuses/update
|
|
- statuses/destroy/:id
|
|
- favorites/create
|
|
- favorites/destroy
|
|
|
|
# How
|
|
## API Key Registration
|
|
### 1.Write Key into code
|
|
write api key into code and create Key object use it.
|
|
```
|
|
#include "cocoatweet/oauth/key.h"
|
|
|
|
auto consumerKey = "your consumer key";
|
|
auto consumerSecret = "your consumer secret";
|
|
auto accessToken = "your access token";
|
|
auto accessTokenSecret = "your access token secret";
|
|
|
|
CocoaTweet::OAuth::Key key(consumerKey, consumerSecret, accessToken, accessTokenSecret);
|
|
|
|
```
|
|
|
|
|
|
### 2. Load Key from JSON file
|
|
prepare file which written 'api-key' with json format.
|
|
```
|
|
{
|
|
"consumer_key" : "your consumer key",
|
|
"consumer_secret" : "your consumer secret",
|
|
"access_token" : "your access token",
|
|
"access_token_secret" : "your access token secret"
|
|
}
|
|
```
|
|
|
|
then you can load api key from json file.
|
|
```
|
|
#include "cocoatweet/oauth/key.h"
|
|
|
|
CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key::fromJsonFile("api_key.json");
|
|
```
|
|
|
|
## Generate API object
|
|
generating API object with Key.
|
|
this object is API entry point.
|
|
|
|
```
|
|
#include "cocoatweet/api/api.h"
|
|
|
|
CocoaTweet::API::API api(key);
|
|
|
|
```
|
|
|
|
## Use API
|
|
```
|
|
// Post a tweet
|
|
api.status().Update("Hello, World!!\nTweet from Cocoa Twitter Library");
|
|
|
|
// Delete a tweet
|
|
api.status().Destroy("tweet id");
|
|
|
|
// Fav. a tweet
|
|
api.favorite().Create("tweet id");
|
|
|
|
// un Fav. a tweet
|
|
api.favorite().Destroy("tweet id");
|
|
```
|