2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Qiita APIのNode.jsクライアントで限定公開記事を投稿してみる。

Last updated at Posted at 2014-12-31

前回の続きです。

今回は記事を投稿してみます。

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経由で投稿された記事はこちらです。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?