Search results for 'RPCXML'. 3 post(s) found.

  1. 2008/01/07 XMLRPC example
  2. 2008/01/07 How to upload attachments such as image by metaWeblog API ?
  3. 2008/01/02 How to post blog content by metaweblog API ? (3)
2008/01/07 16:36

XMLRPC example


Following is the simple XMLRPC example showing the usage.

<html>
<head>
<title>XML-RPC PHP Demo</title>
</head>
<body>
<h1>XML-RPC PHP Demo</h1>

<?php
include 'xmlrpc.inc';

// Make an object to represent our server.
$server = new xmlrpc_client('/api/sample.php',
                            'xmlrpc-c.sourceforge.net', 80);

// Send a message to the server.
$message = new xmlrpcmsg('sample.sumAndDifference',
                         array(new xmlrpcval(5, 'int'),
                               new xmlrpcval(3, 'int')));
$result = $server->send($message);

// Process the response.
if (!$result) {
    print "<p>Could not connect to HTTP server.</p>";
} elseif ($result->faultCode()) {
    print "<p>XML-RPC Fault #" . $result->faultCode() . ": " .
        $result->faultString();
} else {
    $struct = $result->value();
    $sumval = $struct->structmem('sum');
    $sum = $sumval->scalarval();
    $differenceval = $struct->structmem('difference');
    $difference = $differenceval->scalarval();
    print "<p>Sum: " . htmlentities($sum) .
        ", Difference: " . htmlentities($difference) . "</p>";
}
?>

</body></html>
Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 05:01 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 13:49 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:43 delete

    moneyideas

2008/01/07 14:24

How to upload attachments such as image by metaWeblog API ?


Actually this is one of the very important feature to post blog stuffs by Metaweblog API.

Followings are the simple example of posting attachment by Metaweblog API. Actually the unique filename should be passed as third parameter, but the blow sample code automatically extract the file name from the file source.


<?

//requires xmlrpc.inc from http://phpxmlrpc.sourceforge.net/
require_once('xmlrpc.inc');

$g_blog_url = "http://testurl.kurapa.com/api/";
$g_id = "***********";
$g_passwd = "*******";

$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';

function metaWeblog_newMediaObject( $blogid, $file_source, $file_name="")
{
  global $g_id;
  global $g_passwd;
  global $g_blog_url;
 
  // file name extraction from file source in case of having no file name as the third parameter
  if ($file_name=="")
  {
    $p=0;
    $file_len = strlen($file_source);
    for($i=0; $i<$file_len; $i++)
    {
      if ($file_source[$i]=='/') $p=$i+1;
    }
   
    for( $i=$p; $i<$file_len; $i++) $file_name .= $file_source[$i];
  }
 
  // load file content
  $fp=fopen($file_source, "rb");
  if (!$fp) return null; // file open failure !!
  while( !feof($fp))
  {
    $file_content .= fread( $fp, 1024); // 1024 is the server compatible buffer size
    flush();
    @ob_flush();
  }
  fclose($fp);   
 
  $client = new xmlrpc_client( "{$g_blog_url}");
  $f = new xmlrpcmsg("metaWeblog.newMediaObject", // metaWeblog.newMediaObject Method
    array(
      new xmlrpcval("{$blogid}", "string"), // blogid.
      new xmlrpcval($g_id, "string"), // user ID.
      new xmlrpcval($g_passwd, "string"), // password.
      new xmlrpcval( // attachment body
       array(
         'name'  => new xmlrpcval($file_name, "base64"),
         'bits' => new xmlrpcval($file_content, "base64"),
        ), "struct")
    )
  );

  $f->request_charset_encoding = 'UTF-8';

  $response = $client->send($f);
 
  return $response;
}

Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/28 22:58 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 07:13 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:43 delete

    moneyideas

2008/01/02 15:59

How to post blog content by metaweblog API ?


"Metaweblog API" is very usefull when you want to post content automatically or periodically. For example, if you are planning to release news letter by collecting the recent articles on your blog, this is very useful tool.

The below module is available with tistory blog. You can also try to other blogs supporting Metaweblog API. As I mentioned in other article, Microsoft Windows Live Writer is also using this kind of technology to post blog stuffs.

In order to post content by Metaweblog API, you need XMLRPC.inc module on the same working directory.

<?php
//requires XMLRPC.inc from http://phpXMLRPC.sourceforge.net/
require_once('XMLRPC.inc');

$g_blog_url = "http://demoblog.kurapa.com/api/";
$g_id = "kurapa@kurapa.com";
$g_passwd = "*****";

$GLOBALS['XMLRPC_internalencoding'] = 'UTF-8';

function metaWeblog_newPost( $blogid, $title, $content, $tags, $category="")
{
  global $g_id;
  global $g_passwd;
  global $g_blog_url;
 
  $client = new XMLRPC_client( "{$g_blog_url}");
  $f = new XMLRPCmsg("metaWeblog.newPost", // metaWeblog.newPost method
    array(
      new XMLRPCval("{$blogid}", "string"), // blogid.
      new XMLRPCval($g_id, "string"), // user ID.
      new XMLRPCval($g_passwd, "string"), // password
      new XMLRPCval( // body
          array(
            'title'        => new XMLRPCval($title, "base64"),
            'description'    => new XMLRPCval($content, "base64"),
            'category'    => new XMLRPCval($category, "base64"),
            'mt_keywords' => new XMLRPCval($tags, "base64")
        ), "struct"),
      new XMLRPCval(true, "boolean") // publish
    )
  );

  $f->request_charset_encoding = 'UTF-8';

  $response = $client->send($f);
}

metaWeblog_newPost( 0, "test title", "content should be added here", "tag1,tag2");

?>

Trackback 9 Comment 3

Trackback : Cannot send a trackbact to this post.

  1. Subject Russian incest.

    Tracked from Incest forum. 2009/02/11 16:52 delete

    Incest motherson. Taboo incest forum.

  2. Subject Tramadol wikipedia the free encyclopedia.

    Tracked from Tramadol fda. 2009/05/21 07:42 delete

    Tramadol. Tramadol cheap no rx free overnight shipping. What is tramadol.

  3. Subject Cheap tramadol.

    Tracked from Tramadol. 2009/05/22 07:33 delete

    Tramadol ultam.

  4. Subject Xanax overdose.

    Tracked from Xanax. 2009/05/25 09:22 delete

    Xanax 2 mg 180 pills. No rx online xanax.

  5. Subject Valium.

    Tracked from Valium side effects. 2009/06/01 08:58 delete

    Valium side effects. Valium 5mg how long in system. Valium no prescription. No prescription valium. What does valium look like. Buy valium online. Valium.

  6. Subject Taking valium while breast feeding.

    Tracked from Valium 5mg how long in system. 2009/06/17 06:00 delete

    Valium no prescription. Buy valium c.o.d.. Lorazepam to valium conversion. What does valium look like. Valium liquid form. Valium dose appropriate. Valium.

  7. Subject different money making ideas

    Tracked from moneyideas 2010/01/28 23:46 delete

    moneyideas

  8. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 08:10 delete

    moneyideas

  9. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:42 delete

    moneyideas