Welcome Guest, Not a member yet? Register   Sign In
xml-rpc: blogger api question
#1

[eluser]gerben[/eluser]
I'd like to add an xml-rpc interface to my system, using the blogger api. There isn't much documentation or discussion about this, but I thought I'd give it a try.

I debug the code using xml-rpc client Ecto on osx, and when I connect the client sends a request for blogger.getUsersBlogs, and my server returns the expected response.

Normally though, after that a request is sent for blogger.getRecentPosts and blogger.getUserInfo, but the client doesn't do this in my case. The progress bar just keeps on spinning forever, but in the console I can see that no further request to the server is sent.

My guess would be that either: something in the first response doesn't meet the client's "expectations", or somethings's wrong with my blogger.getRecentPosts method handling.

Below is my code, based on the example in the CI manual. For testing purposes I've commented out the user-authentication part, and added some dummy-data. any thoughts on what the problem could be are very welcome, because I feel it must be something small and silly.


Code:
function index()
    {
    
    
        $this->load->library('xmlrpc');
        $this->load->library('xmlrpcs');
        
        
        $config['functions']['blogger.getUsersBlogs'] = array('function' => 'Server.getUserBlogs');
        $config['functions']['blogger.getRecentPosts'] = array('function' => 'Server.getRecentPosts');
        $config['functions']['blogger.getUserInfo'] = array('function' => 'Server.getUserInfo');
        
        
        $this->xmlrpcs->initialize($config);
        $this->xmlrpcs->serve();
    }
    
  
    
    
    function getUserInfo($request)
    {
    
            $username = 'smitty';
            $password = 'smitty';
    
            $this->load->library('xmlrpc');
        
            $parameters = $request->output_parameters();
      
            
        
            $response = array(array('nickname'  => array('Smitty','string'),
                                    'userid'    => array('99','int'),
                                    'url'       => array('http://yoursite.com','string'),
                                    'email'     => array('[email protected]','string'),
                                    'lastname'  => array('Smith','string'),
                                    'firstname' => array('John','string')
                                    ),
                             'struct');
    
            return $this->xmlrpc->send_response($response);
            
        

    }
    
    
    function getUserBlogs($request)
    {
    
            $username = 'smitty';
            $password = 'smitty';
    
            $this->load->library('xmlrpc');
        
        
            $response = array(array(
            'isAdmin' => array('1', 'int'),
            'url'  => array('http://yoursite.com','string'),
                                    'blogName'    => array('My Blog','string'),
                                    'blogid'       => array('1','int'),
                                    'xmlrpc' => array('http://www.zomp.nl/server','string')
                                    
                                    ),
                             'struct');
    
            return $this->xmlrpc->send_response($response);
            
        

    }
    
    
    function getRecentPosts($request)
    {
    
            $username = 'smitty';
            $password = 'smitty';
    
            $this->load->library('xmlrpc');
        
        
            $parameters = $request->output_parameters();
        
        
            $response = array(array('link'  => array('http://yoursite.com','string'),
                                    'permaLink'    => array('http://zomp.nl/zomplog','string'),
                                    'userid'       => array('123','int'),
                                    'mt_allow_pings'     => array('0','int'),
                                    'mt_allow_comments'     => array('1','int'),
                                    'description'    => array('bla bla','string'),
                                    'mt_convert_breaks'    => array('__default__','string'),
                                    'postid'    => array('1234','int'),
                                    'mt_excerpt'    => array('lala','string'),
                                    'mt_keywords'    => array('lala','string'),
                                    'title'    => array('This is my post','string'),
                                    'mt_text_more'    => array('lalili','string'),
                                    'dateCreated'  => array('2005-12-13T01:35:00Z','dateTime.iso8601')
                                    ),
                             'struct');
    
            return $this->xmlrpc->send_response($response);
            
        

    }
#2

[eluser]tunelko[/eluser]
Hi!

There's another way to use Google Services integrating the Gdata part of Zend and CI This is made by the use of 'hooks'. So, let's start to explain how.

First of all, In CI config.php enable $config['enable_hooks'] = TRUE;

Then download the latest Zend Gdata part here:
http://framework.zend.com/download/gdata

Next, copy the library folder to your system/applications:
cp -Rf ZendGdata-[VERSION]/library/* system/applications/Gdata/

In system/applications/config edit your hooks.php and put this pre_controler action:

Code:
$hook['pre_controller'][] = array(
'class' => 'Gdata',
'function' => 'index',
'filename' => 'Gdata.php',
'filepath' => 'hooks'
);

Only one step more, put a file called Gdata.php in the hooks folder that contains this lines of code:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Gdata
{

    function index()
    {

       ini_set('include_path',ini_get('include_path').':'.BASEPATH.'app/Gdata');
    }

}

So you have the Google Data services enabled to use from CI. An example to get all post from a blog, in controllers:

Code:
<?php

class Test extends Controller {
    
function Test() {
        parent::Controller();
        require_once('Zend/Loader.php');
        Zend_Loader::loadClass('Zend_Gdata');
        Zend_Loader::loadClass('Zend_Gdata_Query');
        Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    }
     function index() {
        $user = 'user'; // replace here with your data
        $pass = 'passwd';  // replace here with your data
        $service = 'blogger';
        $BlogID = 'BlogID';

        $client = Zend_GData_ClientLogin::getHttpClient($user, $pass, $service);
        $gdClient = new Zend_Gdata($client);
        $query = new Zend_Gdata_Query('http://www.blogger.com/feeds/default/blogs');
        $feed = $gdClient->getFeed($query);

        $this->get_all_posts($gdClient, $BlogID);
    }

     function get_post($feed) {
// Let's start to retrieve the xml data
        foreach ($feed->entries as $entry) {
            echo "<h1>" . $entry->title->text . "</h1><br>\n";
            echo "<p>" . $entry->content->text . "</p><hr>\n";
        }
    }

     function get_all_posts($gdClient, $BlogID) {
        $query = new Zend_Gdata_Query('http://www.blogger.com/feeds/' . $BlogID . '/posts/default');
        $feed = $gdClient->getFeed($query);
        $this->get_post($feed);
    }

}

P.S: Only one thing. In Zend App.php line 815 there's a line that instance a name of class Zend_Gdata_Feed that doesn't exists, replace or debug why, the right class is Zend_Gdata_App_Feed.




Theme © iAndrew 2016 - Forum software by © MyBB