Forum rules
Under no circumstances is spamming or advertising of any kind allowed. Do not post any abusive, obscene, vulgar, slanderous, hateful, threatening, sexually-orientated or any other material that may violate others security. Profanity or any kind of insolent behavior to other members (regardless of rank) will not be tolerated. Remember, what you don’t find offensive can be offensive to other members. Please treat each other with the kind of reverence you’d expect from other members.
Failure to comply with any of the above will result in users being banned without notice. If any further details are needed, contact: “The team” using the link at the bottom of the forum page. Thank you.
henriqueweiand
Posts: 1
Joined: Fri Feb 10, 2017 8:49 pm

XML-RPC Example?

Fri Feb 10, 2017 8:54 pm

I do not know very well this type of consumption of api (XML-RPC), could someone contribute in this topic, with some example of client so that I can develop something on top? PHP client of course!

vespino
Posts: 23
Joined: Sat Apr 08, 2017 9:57 am

Re: XML-RPC Example?

Sat Apr 08, 2017 10:04 am

This should work, at least it does for me:

Code: Select all

<?php
//xmlrpc function
function xmlrpc_call($url, $methodName, $callvars) {
   //request
   $request=xmlrpc_encode_request($methodName, $callvars, array('encoding'=>'utf-8'));

   //context
   $context=stream_context_create(array('http'=>array('method'=>'POST', 'header'=>'Content-Type: text/xml', 'content'=>$request)));

   //response
   if(!$response=@file_get_contents($url, false, $context)) {
      //set error
      return 'Error occured in setting data from xml-rpc [file_get_contents]';
   }else{
      //decode
      $xmlrpc=xmlrpc_decode($response, 'utf-8');

      //xmlrpc_is_fault
      if(xmlrpc_is_fault($xmlrpc)) {
         //fault
         $data[0]['fault']=$xmlrpc['faultCode'];
         //faultString
         $data[1]['faultString']=$xmlrpc['faultString'];
      }else{
         //set data
         $data=$xmlrpc;
      }
   }

   return $data;
}

//login to opensubtitles
$LogIn=xmlrpc_call(
    $xmlrpc_url,
    'LogIn',
    array(
        'user',
        'pass',
        'language',
        'useragent'
    )
);

//set token
$token=$LogIn['token'];

//queries
$queries[]=array(
    'query'=>'Prison Break',
    'sublanguageid'=>'eng',
    'season'=>1,
    'episode'=>1
);

//SearchSubtitles
$SearchSubtitles=xmlrpc_call(
    $xmlrpc_url,
    'SearchSubtitles',
    array(
        $token,
        $queries
    )
);

print_r($SearchSubtitles);
?>

Return to “Developing”

Who is online

Users browsing this forum: No registered users and 2 guests