README.mdの追加
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
# CocoaTweet
|
||||||
|
This is a library for using Twitter API from C++
|
||||||
|
|
||||||
|
# Dependency
|
||||||
|
- libcurl
|
||||||
|
- libssl
|
||||||
|
|
||||||
|
# Features
|
||||||
|
- statuses/update
|
||||||
|
|
||||||
|
Now, only post a tweet.
|
||||||
|
|
||||||
|
# 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);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Post Tweet
|
||||||
|
post tweet
|
||||||
|
```
|
||||||
|
api.status().Update("Hello, World!!\nTweet from Cocoa Twitter Library");
|
||||||
|
```
|
||||||
+2
-11
@@ -1,21 +1,12 @@
|
|||||||
#include "cocoatweet/oauth/key.h"
|
#include "cocoatweet/oauth/key.h"
|
||||||
#include "cocoatweet/api/api.h"
|
#include "cocoatweet/api/api.h"
|
||||||
|
|
||||||
// 下記で使用しているAPI Keyはほぼ本物です.
|
|
||||||
// (再生成したので使用できないが,こんな感じで登録)
|
|
||||||
auto main() -> int {
|
auto main() -> int {
|
||||||
auto consumerKey = "JRKUmkKFWiC3f7K6msLKaNNuP";
|
|
||||||
auto consumerSecret = "dTGI49MHRqa7XIFiPjwJR27vwolzsRaRXKA48iFlwAv4LK9Vlm";
|
|
||||||
auto accessToken = "2224351076-uF2XTmYeDdAfIsixuvfrwt8puLiPuwGe4w7RM8I";
|
|
||||||
auto accessTokenSecret = "dpCctbxzMjQ9AjZ6V7Fs6TIQlpPJo7JEkmjMfSO7QCEpW";
|
|
||||||
|
|
||||||
// キーオブジェクトを作成
|
// キーオブジェクトを作成
|
||||||
CocoaTweet::OAuth::Key key(consumerKey, consumerSecret, accessToken, accessTokenSecret);
|
CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key::fromJsonFile("test.json");
|
||||||
|
|
||||||
// 作成したキーオブジェクトを用いてAPIを立ち上げる.
|
// 作成したキーオブジェクトを用いてAPIを立ち上げる.
|
||||||
// 内部的にはキーオブジェクトを使用してOAuth認証機を立ち上げている.
|
// 内部的にはキーオブジェクトを使用してOAuth認証機を立ち上げている.
|
||||||
CocoaTweet::API::API api(key);
|
CocoaTweet::API::API api(key);
|
||||||
|
|
||||||
// クエリ文字列をURLエンコードしてないので,空白とか日本語とかはまだ無理.
|
api.status().Update("CocoaTwitterLibraryからテストツイートしています.\n昨日の反省を生かしてAPI-KeyをJsonファイルから読み込めるようにしたよ");
|
||||||
api.status().Update("test");
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user