I have implemented the Twitter Datasource found in the bakery [
http://bakery.cakephp.org/articles/view/twitter-datasource ] which
uses Http Socket to send a GET request to Twitter, and parses the XML
response into an array.

Everything works great about 95% of the time, however, after long
periods of inactivity (usually my first use of the app of the day),
the request's response is an HTML file with a refresh metadata tag
(with a .1 second content attribute).  This data is transformed into
an array by the __process method of the datasource.  I can debug the
response before it's turned into an array by logging it.  The response
code is 200, success. The entire response is here:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/1999/REC-html401-19991224/strict.dtd">
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd";> -->
<HTML>
<HEAD>
<META HTTP-EQUIV="Refresh" CONTENT="0.1">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<TITLE></TITLE>
</HEAD>
<BODY><P></BODY>
</HTML>

So 2 questions... 1) Is anyone else retrieving this response from
Twitter?  and 2) if this is a response from Twitter, will outputting
the response allow for the refresh to occur?  In other words, will
HTTP socket know how to handle this response if I'm not transforming
it into an array before outputting it?  It's hard for me to test
against this because the error appears inconsistently.

Also probably worth mentioning, I'm using $this->disableCache() in my
controller, but looking at the disableCache method in /cake/libs/
controller/controller.php, doesn't look like this response is being
generated by Cake.

Here's also a stripped down version of my tweets controller, in case
I'm missing something else that might explain why I'm getting that
response:

    function beforeFilter(){
        parent::beforeFilter();

        /*
         * Load up the ConnectionManager and connect to the Twitter
datasource:
         * http://bakery.cakephp.org/articles/view/twitter-datasource
         * If username and password are set in session after
successful login within
         * index method, set Twitter DS username and password so all
preceeeding
         * requests are authenticated, and don't count against IP rate
limit
         */
        $this->Twitter = ConnectionManager::getDataSource('twitter');
        if($this->Session->read('Twitter.username') && $this->Session-
>read('Twitter.password')):
            $this->Twitter->username = $this->Session->read
('Twitter.username');
            $this->Twitter->password = $this->Session->read
('Twitter.password');
            $this->loggedIn = true;
        endif;

        /*
         * If a user has requested a method other than index, but has
not logged in,
         * send them back to the index method
         */
        if($this->action != 'index' && !$this->loggedIn):
            $this->redirect(array('action' => 'index'));
        endif;

    }

function index(){
        $this->disableCache();

        if($this->loggedIn):
            $this->redirect(array('action' => 'select'));

        elseif(!empty($this->data)):
            $this->Twitter->username = $this->data['Tweet']
['username'];
            $this->Twitter->password = $this->data['Tweet']
['password'];
            $response = $this->Twitter->account_verify_credentials();

            if(isset($response['User'])):
                $this->Session->write('Twitter.username', $this->data
['Tweet']['username']);
                $this->Session->write('Twitter.password', $this->data
['Tweet']['password']);
                $this->Session->write('Twitter.followers', $response
['User']['followers_count']);
                $this->redirect(array('action' => 'select'));

            elseif(isset($response['Hash']['error'])):
                $this->data['Tweet']['password'] = '';
                $this->Session->setFlash('Invalid username or
password.  Please try again.');

            else:
                $this->data['Tweet']['password'] = '';
                debug($response);
                $this->Session->setFlash('Twitter returned something
unexpected:' . $response);

            endif;

        endif;
        }

function select($page = 1){
        $this->disableCache();

        //this is just a method that retrieves a list of the logged in
user's followers
        //either retrieved from cache, or via datasource if proper
cache file isn't found...
        $this->set('followers', $this->_getFollowers($page));
        $this->set('page', $page);


        if($this->RequestHandler->isAjax()):
            $this->render('select_more');
        endif;
    }


Thanks in advance!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to