Welcome Guest, Not a member yet? Register   Sign In
XML-RPC + Livejournal posting problem [SOLVED]
#1

[eluser]GIN[/eluser]
Hi.

I'm trying to send data to my livejournal account but got a strange error.
This is my code sample:
Code:
$name = "username";
$password = "password";
$text = "Some kind of text";
$subj = "Subject";
$this->load->library('xmlrpc');
$this->xmlrpc->server('http://www.livejournal.com/interface/xmlrpc', 80);
$this->xmlrpc->method('LJ.XMLRPC.postevent');
$date = time();
$year = date("Y", $date);
$mon = date("m", $date);
$day = date("d", $date);
$hour = date("G", $date);
$min = date("i", $date);
$post = array(    array("username" => array($name, "string")),
            array("password" => array($password, "string")),
            array("event" => array($text, "string")),
            array("subject" => array($subj, "string")),
            array("lineendings" => array("unix", "string")),
            array("year" => array($year, "int")),
            array("mon" => array($mon, "int")),
            array("day" => array($day, "int")),
            array("hour" => array($hour, "int")),
            array("min" => array($min, "int")),
            array("ver" => array(2, "int"))
    );
$this->xmlrpc->request($post);
if (!$this->xmlrpc->send_request())
{
   print_r($this->xmlrpc->display_error());
}
All data corrent. I'm using utf-8 charset.
And so I got this error:
"Can't use string ("Array") as a HASH ref while "strict refs" in use at /home/lj/cgi-bin/Apache/LiveJournal.pm line 1779."

What I'm doing wrong?
Thanks
#2

[eluser]xzela[/eluser]
That might be a pearl error, on livejournals side.

So, you may be out of luck.

Have you seen an example where this does work? Does livejournal have an API?
#3

[eluser]GIN[/eluser]
I've seen examples with non-CI classes but didn't use them. I should try, I guess.
#4

[eluser]GIN[/eluser]
I tried Inutio XML-RPC Library. It works, but as I can see it write to socket, but not use xml-rpc features.
So I have 2 options:
1. My code sucks.
2. Livejournals perl-side sucks.

Any ideas?
#5

[eluser]GIN[/eluser]
Code:
class LiveJournal extends Controller {
      
  private $LJ_url = 'http://www.livejournal.com/interface/xmlrpc';
  private $LJ_login = 'your login';
  private $LJ_pass = 'your pass';
        
  function LiveJournal()
  {
    parent::Controller();
    $this->load->library('xmlrpc');
  }
        
  function index()
  {
    $this->xmlrpc->server($this->LJ_url);
    $this->xmlrpc->method('LJ.XMLRPC.getchallenge');

    if (!$this->xmlrpc->send_request()) {
      echo $this->xmlrpc->display_error();
    }
    else {
      $challenge_response = $this->xmlrpc->display_response();
      $request = array(
                   array(
                      array(
                          'username'=>array($this->LJ_login,'string')
                          ,'auth_method'=>array('challenge','string')
                          ,'auth_challenge'=>array($challenge_response['challenge'],'string')
                          ,'auth_response'=>array(md5($challenge_response['challenge'].md5($this->LJ_pass)),'string')
                          ,'ver'=>array(2,'int')
                          ,'event'=>array('Post text','string')
                          ,'subject'=>array('Post subject','string')
                          ,'year'=>array(2009,'int')
                          ,'mon'=>array(11,'int')
                          ,'day'=>array(12,'int')
                          ,'hour'=>array(5,'int')
                          ,'min'=>array(27,'int')
                          ,'props'=>array(
                              array(
                                  'opt_backdated'=>array(true,'boolean')
                                  ,'taglist'=>array('tag 1, tag 2, tag 3','string')
                              )
                              ,'struct')
                          ,'security'=>array('public','string')
                      )
                      ,'struct'
                   )
                 );
      
      $this->xmlrpc->method('LJ.XMLRPC.postevent');
      $this->xmlrpc->request($request);
      if (!$this->xmlrpc->send_request()) {
        echo $this->xmlrpc->display_error();
      }
      else {
        $postData = $this->xmlrpc->display_response();
        //$postData['url'] – here url of your post
      }
    }
  }
}
Thanks to Vladimir who [url="http://www.simplecoding.org/xml-rpc-codeigniter-livejournal-i-kucha-problem.html"]solved[/url] this problem.

First of all - be careful when prepare array for posting!

And also I've got problems with posting on localhost with russian texts only, but on hosted server it works awesome.




Theme © iAndrew 2016 - Forum software by © MyBB