TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
Kohana 3 OAuth Make Request
  • Hi all,

    I'm trying to get to grips with the OAuth module provided with Kohana 3. I have managed to get the necessary access tokens from Twitter but for some reason I just can't figure out how to make a request e.g. to post an update or grab recent tweets. I thought it would be via the OAuth_Request class but I'm tearing my hair out trying to work out what it's expecting. Can anyone provide a piece of sample code or explanation on how to get it running?

    Thanks,
    Luke.
  • callback

    // save access token cookies
    Cookie::set('token', $token->token);
    Cookie::set('secret', $token->secret);
    

    where you want user data

    $consumer = OAuth_Consumer::factory(Kohana::config('oauth.twitter'));
    $options['token'] = Cookie::get('token', NULL);
    $options['secret'] = Cookie::get('secret', NULL);
    $access_token = OAuth_Token::factory('access', $options);
    
    $r = Twitter::factory('account');
    $response = $r->verify_credentials($consumer, $access_token);
    
    $view = View::factory('pages/dev');
    $view->content = 'logged in as: '.$response->screen_name;
    $this->request->response = $view->render();
    
  • I'm getting an exception on the line:
    $r = Twitter::factory('account');
    Seems I don't have a Twitter class. To be clear, I'm using the http://github.com/kohana/oauth module.
    Thanks.
  • Sorry about that, I use shadowhand's service api module as well.

    http://github.com/shadowhand/apis
  • I'm having the same problem getting started. My problem is simple, but the solution doesn't seem to be...

    I was away from Twitter for eleven days (since August 20) and I want to read all the tweets that I've missed. You'd think there would be an easy way to do this (since a lot of people go on vacation and can't always check Twitter) but it seems like the only way to accomplish this is to create an app through the API. Simple problem, not so simple solution...

    So, Twitter's API will allow me to view my home timeline (http://dev.twitter.com/doc/get/statuses/home_timeline) and use the "since_id" parameter to get the right tweets. I've been using since_id=21865567171 (from http://twitter.com/DanielMenjivar/status/21865567171) - as long as I can get the RSS source and view it in Safari, that's good enough.

    I installed a fresh copy of Kohana 3.0.7 as well as ShadowHand's Twitter API module on my MacBook Pro and am able to get the home timeline, but only if I don't specify the "since_id" parameter. When I specify any parameter, I get an "incorrect signature" error.

    I created a new Twitter App and got a consumer key and secret and set those up in the Kohana oAuth config file. I also got my Access Token and Access Token Secret from Twitter (http://dev.twitter.com/apps -> Edit details -> Application Detail -> My Access Token)

    I'm using the code above (slightly modified with the access token and secret hardcoded in) and here's what I have:

    $consumer = OAuth_Consumer::factory(Kohana::config('oauth.twitter'));
    $options['token'] = 'MY ACCESS TOKEN HERE';
    $options['secret'] = 'MY ACCESS TOKEN SECRET HERE';
    $access_token = OAuth_Token::factory('access', $options);

    $r = Twitter::factory('statuses');

    $params = array('since_id' => 21865567171);
    $response = $r->home_timeline($consumer, $access_token, $params);

    $view = View::factory('pages/dev');
    $view->content = $response;
    $this->request->response = $view->render();


    I created a 'pages/dev' view to just var_dump the response for now. It works fine when you remove the $params from the request, but not with the $params included.

    Oh yeah, the twitter/statuses class I created is a direct copy of ShadowHand's "account" class, except the url was changed to statuses/home_timeline and I'm not parsing the result.

    I read somewhere that any parameters that are added to the request must also be included when creating a signature, and it doesn't seem that the oAuth library that comes with Kohana is doing that, but I'm not about to second-guess Kohana - I realize the problem is likely something I'm doing. But what?

    Thanks in advance!

    DM