【WordPress】XMLRPCでのレスポンス

公開日:
更新日:
カテゴリー: WordPress

XMLRPCに関する個人的メモ

XMLRPCで記事を投稿したときのレスポンス

メソッド「metaWeblog.newPost」でWordPressサイトに対して遠隔投稿した際に返ってくるレスポンスはこのようになっている。

XML_RPC_Response Object
(
    [xv] => XML_RPC_Value Object
        (
            [me] => Array
                (
                    [string] => 470 //投稿した記事のポストID
                )

            [mytype] => 1
        )

    [fn] => 
    [fs] => 
    [hdrs] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Date: Fri, 14 Mar 2014 20:08:30 GMT
            [2] => Server: Apache
            [3] => Connection: close
            [4] => Content-Length: 178
            [5] => Content-Type: text/xml; charset=UTF-8
        )

)

投稿した記事のポストIDを取得する場合

$post_id = $response->xv->me['string'];

XMLRPCでカテゴリーを作成した場合のレスポンス

メソッド「wp.newCategory」でWordPressサイトに対して遠隔でカテゴリーを作成した場合、次のレスポンスが返ってくる

XML_RPC_Response Object
(
    [xv] => XML_RPC_Value Object
        (
            [me] => Array
                (
                    [int] => 126 //作成したカテゴリーID
                )

            [mytype] => 1
        )

    [fn] => 
    [fs] => 
    [hdrs] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Date: Fri, 14 Mar 2014 20:19:33 GMT
            [2] => Server: Apache
            [3] => Connection: close
            [4] => Content-Length: 172
            [5] => Content-Type: text/xml; charset=UTF-8
        )

)

作成したカテゴリーIDを取得する場合

$category_id = $response->xv->me['int'];

XMLRPCでファイルのアップロードをした時のレスポンス

メソッド「wp.uploadFile」を利用してWordPressサイトに遠隔でファイルをアップロードしたときのレスポンス

XML_RPC_Response Object
(
    [xv] => XML_RPC_Value Object
        (
            [me] => Array
                (
                    [struct] => Array
                        (
                            [id] => XML_RPC_Value Object
                                (
                                    [me] => Array
                                        (
                                            [string] => 474 //アップロードしたファイルのアタッチメントID
                                        )

                                    [mytype] => 1
                                )

                            [file] => XML_RPC_Value Object
                                (
                                    [me] => Array
                                        (
                                            [string] => ○○○.jpg //アップロードしたファイル名
                                        )

                                    [mytype] => 1
                                )

                            [url] => XML_RPC_Value Object
                                (
                                    [me] => Array
                                        (
                                            [string] => http://○○○.com/wp-content/uploads/○○○.jpg //アップロードしたファイルのURL
                                        )

                                    [mytype] => 1
                                )

                            [type] => XML_RPC_Value Object
                                (
                                    [me] => Array
                                        (
                                            [string] => image/gif
                                        )

                                    [mytype] => 1
                                )

                        )

                )

            [mytype] => 3
        )

    [fn] => 
    [fs] => 
    [hdrs] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Date: Fri, 14 Mar 2014 21:01:52 GMT
            [2] => Server: Apache
            [3] => Connection: close
            [4] => Content-Length: 530
            [5] => Content-Type: text/xml; charset=UTF-8
        )

)

アップロードしたファイルのアタッチメントID、ファイル名、ファイルURLを取得する場合

    $upfile_attachment_id = $response->xv->me['struct']['id']->me['string'];
    $upfile_name = $response->xv->me['struct']['file']->me['string'];
    $upfile_url = $response->xv->me['struct']['url']->me['string'];

XMLRPCでカテゴリー情報を取得したときのレスポンス

メソッド「wp.getCategories」を利用してWordPressサイトの全カテゴリー情報を取得したときのレスポンス

XML_RPC_Response Object
(
    [xv] => XML_RPC_Value Object
        (
            [me] => Array
                (
                    [array] => Array
                        (
                            [0] => XML_RPC_Value Object
                                (
                                    [me] => Array
                                        (
                                            [struct] => Array
                                                (
                                                    [categoryId] => XML_RPC_Value Object
                                                        (
                                                            [me] => Array
                                                                (
                                                                    [string] => 16 //カテゴリーID
                                                                )

                                                            [mytype] => 1
                                                        )

                                                    [parentId] => XML_RPC_Value Object
                                                        (
                                                            [me] => Array
                                                                (
                                                                    [string] => 0 //親カテゴリーのID
                                                                )

                                                            [mytype] => 1
                                                        )

                                                    [description] => XML_RPC_Value Object
                                                        (
                                                            [me] => Array
                                                                (
                                                                    [string] => ○○○ //概要
                                                                )

                                                            [mytype] => 1
                                                        )

                                                    [categoryDescription] => XML_RPC_Value Object
                                                        (
                                                            [me] => Array
                                                                (
                                                                    [string] => ~~~~~~  //カテゴリーの概要
                                                                )

                                                            [mytype] => 1
                                                        )

                                                    [categoryName] => XML_RPC_Value Object
                                                        (
                                                            [me] => Array
                                                                (
                                                                    [string] => ○○○ //カテゴリー名
                                                                )

                                                            [mytype] => 1
                                                        )

                                                    [htmlUrl] => XML_RPC_Value Object
                                                        (
                                                            [me] => Array
                                                                (
                                                                    [string] => http://○○○.com/△△ //カテゴリーのURL
                                                                )

                                                            [mytype] => 1
                                                        )

                                                    [rssUrl] => XML_RPC_Value Object
                                                        (
                                                            [me] => Array
                                                                (
                                                                    [string] => http://○○○.com/△△/feed //カテゴリーのRSSURL
                                                                )

                                                            [mytype] => 1
                                                        )

                                                )

                                        )

                                    [mytype] => 3
                                )


                            ・
                            ・以下略
                            ・

                        )

                )

            [mytype] => 2
        )

    [fn] =>
    [fs] =>
    [hdrs] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Date: Fri, 14 Mar 2014 22:06:11 GMT
            [2] => Server: Apache
            [3] => Connection: close
            [4] => Content-Length: 7042
            [5] => Content-Type: text/xml; charset=UTF-8
        )

)

カテゴリーIDとカテゴリー名を取得(カテゴリーは複数あって配列に格納されているのでループで取り出す)

foreach($response->xv->me["array"] as $item){
  echo $item->me["struct"]["categoryId"]->me["string"];
  echo ":";
  echo $item->me["struct"]["categoryName"]->me["string"];
  echo "<br />";
}

 

 

 

 

 

 

 

 

 

あわせて読んでほしい!

 

コメント

まだコメントはありません。

コメントフォーム
お名前
コメント