前回の続きです。
- http://qiita.com/n0bisuke/items/4587f42dce3218960730
- http://qiita.com/n0bisuke/items/6d7d92eac9f1b0782226
今回は記事を投稿してみます。
create_item()
というメソッドを使ってみます。
create_items(オプション)という使い方みたいです。
参考: http://qiita.com/api/v2/docs#投稿
とりあえず使ってみる
qiita.js
// require in commonjs env
var Qiita = require('qiita-js');
// set your token
Qiita.setToken('your access token');
//setting post options
var options = {
"body": "# API経由で投稿しています。",
"coediting": false,
"gist": false,
"private": true,
"tags": [
{
"name": "example",
"versions": [
"0.0.1"
]
}
],
"title": "Qiita API Node.js クライアントから投稿",
"tweet": false
};
//execution api
Qiita.Resources.Item.create_item(options).then(function(res){
console.log(res);
});
限定公開にする場合はprivateの値をtrueにしましょう。
実行してみる
$ node qiita.js
{ rendered_body: '<h1>\n<span id="api経由で投稿しています" class="fragment"></span><a href="#api%E7%B5%8C%E7%94%B1%E3%81%A7%E6%8A%95%E7%A8%BF%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99"><i class="fa fa-link"></i></a>API経由で投稿しています。</h1>\n',
body: '# API経由で投稿しています。\n',
coediting: false,
created_at: '2014-12-31T16:06:03+09:00',
id: 'cf6d9113fdba32cdcea2',
private: true,
tags:
[ { icon_url: 'icons/medium/missing.png',
name: 'example',
versions: [Object] } ],
title: 'Qiita API Node.js クライアントから投稿',
updated_at: '2014-12-31T16:06:03+09:00',
url: 'http://qiita.com/n0bisuke/items/cf6d9113fdba32cdcea2',
user:
{ description: '@のびすけです。\r\n\r\nhttp://liginc.co.jp/author/nobisuke\r\nhttps://www.wantedly.com/users/49472\r\nhttp://offsidenow.phpapps.jp/',
facebook_id: 'sugawara.ryousuke',
followers_count: 69,
followees_count: 23,
github_login_name: 'n0bisuke',
id: 'n0bisuke',
items_count: 107,
linkedin_id: '',
location: '岩手 <-> 上野',
name: 'Sugawara Ryousuke',
organization: 'http://liginc.co.jp',
profile_image_url: 'https://gravatar.com/avatar/dae1d4cc4599a65a5da6e1a1f9d96f05?d=https%3A%2F%2Fidenticons.github.com%2F9a034197db94d3fa733e5079c6eb313a.png&r=x',
twitter_screen_name: 'n0bisuke',
website_url: 'http://liginc.co.jp/member/member_detail?user=nobisuke' } }
投稿できたみたいです。
http://qiita.com/{your qiita id}/private
を確認してみます。
実際にAPI経由で投稿された記事はこちらです。