Help us understand the problem. What is going on with this article?

RubyのXML-RPCを利用してFC2ブログに投稿するサンプル

More than 5 years have passed since last update.

XML-RPCの利用には特にgemは必要ありません。
今回はsinatraを使って、webアプリからAPI経由でFC2に投稿するサンプルを作ってみました。

main.rb
# encoding: utf-8
require 'sinatra'
require 'xmlrpc/client'

get '/fc2/new' do
  erb :new
end

post '/fc2/create' do

  #FC2ブログのエンドポイント
  client = XMLRPC::Client.new2('http://blog.fc2.com/xmlrpc.php')
  #HTTPを圧縮しない
  client.http_header_extra = {'accept-encoding' => 'identity'}

  #ブログID,パスワード、コンテンツ
  blog_id = 'blog_id'
  password = 'password' 
  contents = {
    'title' => 'test',
    'description' => 'test post'
  }

  begin
    #APIリクエスト(新規投稿)
    client.call('metaWeblog.newPost', '', blog_id, password, contents, 1)
  rescue XMLRPC::FaultException => e
    p e.faultCode
    p e.faultString
  end

end

新規投稿時は、metaWeblog.newPostというパラメータでコールしてやるといいです。
PHPによるサンプルやその他の命令については以下に詳しく紹介されています。

http://nekoriki.net/83

また、XML-RPCクライアントのHTTP圧縮によるエラーの回避については下記を参考にさせていただきました。

http://uisteven.blog.fc2.com/blog-entry-44.html

day-1
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした