[twitter-dev] Re: OAuth and Perl

2009-05-19 Thread Jesse Stay
I just blogged a pretty thorough howto on this.  Let me know if you have
feedback:
http://staynalive.com/articles/2009/05/19/social-coding-how-to-code-twitters-oauth-using-netoauth-and-perl/
http://staynalive.com/articles/2009/05/19/social-coding-how-to-code-twitters-oauth-using-netoauth-and-perl/

@Jesse

On Fri, May 15, 2009 at 8:04 PM, ben deutsc...@gmail.com wrote:


 I'm having the same problem as Jesse using the Net::OAuth

 Here's what I get back from twitter:

 $VAR1 = bless( {
 '_protocol' = 'HTTP/1.1',
 '_content' = 'Failed to validate oauth signature or
 token',
 '_rc' = '401',
 '_headers' = bless( {
'connection' = 'close',
'set-cookie' =
 '_twitter_sess=BAh7BiIKZ0xhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
 %250ASGFzaHsABjoKQHVzZWR7AA%253D
 %253D--1164b91ac812d853b877e93ddb612b7471bebc74; domain=.twitter.com;
 path=/',
'cache-control' = 'no-cache,
 max-age=300',
'status' = '401
 Unauthorized',
'date' = 'Sat, 16 May 2009
 01:57:55 GMT',
'vary' = 'Accept-Encoding',
'client-ssl-cert-issuer' = '/
 C=US/O=Equifax Secure Inc./CN=Equifax Secure Global eBusiness CA-1',
'client-ssl-cipher' = 'DHE-
 RSA-AES256-SHA',
'client-peer' =
 '128.121.146.100:443',
'client-warning' = 'Missing
 Authenticate header',
'client-date' = 'Sat, 16 May
 2009 01:57:55 GMT',
'client-ssl-warning' = 'Peer
 certificate not verified',
'content-type' = 'text/html;
 charset=utf-8',
'server' = 'hi',
'client-response-num' = 1,
'content-length' = '43',
'client-ssl-cert-subject' = '/
 C=US/O=twitter.com/OU=GT09721236/OU=See www.rapidssl.com/resources/cps
 (c)08/OU=Domain Control Validated - RapidSSL(R)/CN=twitter.com',
'expires' = 'Sat, 16 May 2009
 02:02:55 GMT'
  }, 'HTTP::Headers' ),
 '_msg' = 'Unauthorized',
 '_request' = bless( {
'_content' = '',
'_uri' = bless( do{\(my $o =
 'https://twitter.com/statuses/update.json?

 oauth_consumer_key=K9ICZr8UwHCVza91AH9Sgoauth_nonce=2AIYDaoQyknJ5Cpqoauth_signature=W
 %2BQu6CG7ENoVNghVyNU4DX%2B2LJM%3Doauth_signature_method=HMAC-
 SHA1oauth_timestamp=1242439075oauth_token=15385100-
 snbvmpiROaexwcJx00gkCegiBwX481bvGsVOmRo8eoauth_version=1.0status=Test
 +message')}, 'URI::https' ),
'_headers' = bless( {
   'user-
 agent' = 'libwww-perl/5.808',

 'content-type' = 'application/x-www-form-urlencoded',

 'content-length' = 0
 },
 'HTTP::Headers' ),
'_method' = 'POST'
  }, 'HTTP::Request' )
   }, 'HTTP::Response' );


 On Apr 30, 6:39 pm, Mario Menti mme...@gmail.com wrote:
  On Thu, Apr 30, 2009 at 11:22 PM, Jesse Stay jesses...@gmail.com
 wrote:
   I just wanted to bring back attention to this.  Has anyone on the list
   gotten Twitter's OAuth to work with Perl?  Care to share some code
 examples?
 
  I'm using Perl's Net::OAuth heavily, but only for updating twitter status
  with existing access tokens (as my backend processing is Perl, while the
  frontend is RoR, so authorisation/key exchange is handled through rails
  OAuth).
 
  I did find one bug which I've reported back to the Net::OAuth CPAN
  maintainer, who said he'll implement in a future release:
 
  The issue relates tohttp://
 code.google.com/p/twitter-api/issues/detail?id=433#c32(there's lots
  of useful into in this thread)
 
  The problem occurs when you pass an extra_param containing certain
 Unicode
  characters. What happens is that the parameter is passed to the signature
  creation, and the signature ends up wrong, leading to 401 errors when
 trying
  to make a request.
 
  The fix for this is actually detailed in the above thread, a problem with
  the regexp doing the escaping. In Perl's case, the below change
  to Net::OAuth's Message.pm fixes this:
 
  sub encode {
 my $str = shift;
 $str =  unless defined $str;
 # return URI::Escape::uri_escape_utf8($str,'^\w.~-');
 # MM, fix based on twitter OAuth bug report
 

[twitter-dev] Re: OAuth and Perl

2009-05-15 Thread ben

I'm having the same problem as Jesse using the Net::OAuth

Here's what I get back from twitter:

$VAR1 = bless( {
 '_protocol' = 'HTTP/1.1',
 '_content' = 'Failed to validate oauth signature or
token',
 '_rc' = '401',
 '_headers' = bless( {
'connection' = 'close',
'set-cookie' =
'_twitter_sess=BAh7BiIKZ0xhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
%250ASGFzaHsABjoKQHVzZWR7AA%253D
%253D--1164b91ac812d853b877e93ddb612b7471bebc74; domain=.twitter.com;
path=/',
'cache-control' = 'no-cache,
max-age=300',
'status' = '401
Unauthorized',
'date' = 'Sat, 16 May 2009
01:57:55 GMT',
'vary' = 'Accept-Encoding',
'client-ssl-cert-issuer' = '/
C=US/O=Equifax Secure Inc./CN=Equifax Secure Global eBusiness CA-1',
'client-ssl-cipher' = 'DHE-
RSA-AES256-SHA',
'client-peer' =
'128.121.146.100:443',
'client-warning' = 'Missing
Authenticate header',
'client-date' = 'Sat, 16 May
2009 01:57:55 GMT',
'client-ssl-warning' = 'Peer
certificate not verified',
'content-type' = 'text/html;
charset=utf-8',
'server' = 'hi',
'client-response-num' = 1,
'content-length' = '43',
'client-ssl-cert-subject' = '/
C=US/O=twitter.com/OU=GT09721236/OU=See www.rapidssl.com/resources/cps
(c)08/OU=Domain Control Validated - RapidSSL(R)/CN=twitter.com',
'expires' = 'Sat, 16 May 2009
02:02:55 GMT'
  }, 'HTTP::Headers' ),
 '_msg' = 'Unauthorized',
 '_request' = bless( {
'_content' = '',
'_uri' = bless( do{\(my $o =
'https://twitter.com/statuses/update.json?
oauth_consumer_key=K9ICZr8UwHCVza91AH9Sgoauth_nonce=2AIYDaoQyknJ5Cpqoauth_signature=W
%2BQu6CG7ENoVNghVyNU4DX%2B2LJM%3Doauth_signature_method=HMAC-
SHA1oauth_timestamp=1242439075oauth_token=15385100-
snbvmpiROaexwcJx00gkCegiBwX481bvGsVOmRo8eoauth_version=1.0status=Test
+message')}, 'URI::https' ),
'_headers' = bless( {
   'user-
agent' = 'libwww-perl/5.808',
 
'content-type' = 'application/x-www-form-urlencoded',
 
'content-length' = 0
 },
'HTTP::Headers' ),
'_method' = 'POST'
  }, 'HTTP::Request' )
   }, 'HTTP::Response' );


On Apr 30, 6:39 pm, Mario Menti mme...@gmail.com wrote:
 On Thu, Apr 30, 2009 at 11:22 PM, Jesse Stay jesses...@gmail.com wrote:
  I just wanted to bring back attention to this.  Has anyone on the list
  gotten Twitter's OAuth to work with Perl?  Care to share some code examples?

 I'm using Perl's Net::OAuth heavily, but only for updating twitter status
 with existing access tokens (as my backend processing is Perl, while the
 frontend is RoR, so authorisation/key exchange is handled through rails
 OAuth).

 I did find one bug which I've reported back to the Net::OAuth CPAN
 maintainer, who said he'll implement in a future release:

 The issue relates 
 tohttp://code.google.com/p/twitter-api/issues/detail?id=433#c32(there's lots
 of useful into in this thread)

 The problem occurs when you pass an extra_param containing certain Unicode
 characters. What happens is that the parameter is passed to the signature
 creation, and the signature ends up wrong, leading to 401 errors when trying
 to make a request.

 The fix for this is actually detailed in the above thread, a problem with
 the regexp doing the escaping. In Perl's case, the below change
 to Net::OAuth's Message.pm fixes this:

     sub encode {
        my $str = shift;
        $str =  unless defined $str;
        # return URI::Escape::uri_escape_utf8($str,'^\w.~-');
        # MM, fix based on twitter OAuth bug report
        return URI::Escape::uri_escape($str,'^0-9a-zA-Z\d._~-');
     }

 I'm not sure if this is relevant to you given your previous messages, but
 thought I'd share just in case. With this fix implemented, it seems to work
 very well, more than 10,000 of my users have migrated to OAuth and I'm doing
 hundreds of thousands OAuth-based status update requests, without obvious
 problems.

 Mario.


[twitter-dev] Re: OAuth and Perl

2009-04-30 Thread Jesse Stay
I just wanted to bring back attention to this.  Has anyone on the list
gotten Twitter's OAuth to work with Perl?  Care to share some code examples?

Thanks,

Jesse

On Wed, Apr 22, 2009 at 1:40 AM, Jesse Stay jesses...@gmail.com wrote:

 Matt, here's what I'm getting back:
 On Tue, Apr 21, 2009 at 9:58 AM, Matt Sanford m...@twitter.com wrote:


 Hi Jesse,

The best debugging information is:

 1. The error message from your 401.
   » Example: Failed to validate oauth signature or token


 Missing authenticate header




 2. The signature base string. In other words, the string you used to
 create the signature.
  » Example: See [1] for an example.


 Any idea how to get this using Perl's Net::OAuth?



 3. What oauth application is this for?
  » Example: http://twitter.com/oauth_clients/details/104


 It's for the SocialToo.com application:
 http://twitter.com/oauth_clients/details/61




 On Apr 20, 2009, at 07:59 PM, Jesse Stay wrote:

  I'm getting 401 Unauthorized when trying to use Net::OAuth in Perl to
 access Twitter - it's happening in trying to swap the request token for the
 access token (in the second block below, from the $ua-post()).  I was just
 wondering what the best method for debugging this would be.  Here's my code
 (it's in Catalyst, so the $c's are from the Framework environment):

 sub authenticate_twitter : Local {
my ($self, $c) = @_;

unless ($c-user_session-{'request_token'} 
 $c-user_session-{'request_token_secret'}) {
my $request = Net::OAuth-request(request token)-new(
consumer_key = $c-config-{'twitter_consumer_key'},
consumer_secret = $c-config-{'twitter_consumer_secret'},
request_url = $c-config-{'twitter_request_url'},
request_method = 'GET',
signature_method = 'HMAC-SHA1',
timestamp = time,
nonce = join('', rand_chars(size=16, set='alphanumeric')),
);
$request-sign();

$c-log-debug(URL: .$request-to_url);

my $ua = LWP::UserAgent-new;
my $res = $ua-get($request-to_url); # post request to Twitter

if ($res-is_success) {
my $response = Net::OAuth-response('request
 token')-from_post_body($res-content);
$c-user_session-{'request_token'} = $response-token;
$c-user_session-{'request_token_secret'} =
 $response-token_secret;

if (defined $c-user_session-{'request_token'}) {
my $auth_url =
 $c-config-{'twitter_authorize_token_url'}.?oauth_token= .
 $c-user_session-{'request_token'} .
 redirect_url=.uri_escape($c-req-param(redi
 rect_url));;
$c-res-redirect($auth_url);
$c-detach;
return;
}
}
else {
$c-log-fatal(Something went wrong.);
}
}
else {
$c-log-debug(request_token:
 .$c-user_session-{'request_token'});
$c-log-debug(request_token_secret:
 .$c-user_session-{'request_token_secret'});
my $request = Net::OAuth-request(access token)-new(
consumer_key= $c-config-{'twitter_consumer_key'},
consumer_secret =
 $c-config-{'twitter_consumer_secret'},
token   = $c-user_session-{'request_token'},
token_secret=
 $c-user_session-{'request_token_secret'},
request_url =
 $c-config-{'twitter_access_token_url'},
request_method  = 'POST',
signature_method= 'HMAC-SHA1',
timestamp   = time,
nonce   = join('', rand_chars(size=16,
 set='alphanumeric')),
);
$request-sign();

$c-log-debug(URL: .$request-to_url);

my $ua = LWP::UserAgent-new;
my $res = $ua-post($request-to_url); # post request to Twitter

if ($res-is_success) {
my $response = Net::OAuth-response('access
 token')-from_post_body($res-content);
$c-user_session-{'access_token'} = $response-token;
$c-user_session-{'access_token_secret'} =
 $response-token_secret;


  $c-res-redirect(uri_unescape($c-req-param('redirect_url')));
}
else {
$c-log-fatal(Could not get an Access Token:  .
 $res-status_line .   . $res-content);
}

}

 }

 -...@jesse






[twitter-dev] Re: OAuth and Perl

2009-04-30 Thread Mario Menti
On Thu, Apr 30, 2009 at 11:22 PM, Jesse Stay jesses...@gmail.com wrote:

 I just wanted to bring back attention to this.  Has anyone on the list
 gotten Twitter's OAuth to work with Perl?  Care to share some code examples?


I'm using Perl's Net::OAuth heavily, but only for updating twitter status
with existing access tokens (as my backend processing is Perl, while the
frontend is RoR, so authorisation/key exchange is handled through rails
OAuth).

I did find one bug which I've reported back to the Net::OAuth CPAN
maintainer, who said he'll implement in a future release:

The issue relates to
http://code.google.com/p/twitter-api/issues/detail?id=433#c32 (there's lots
of useful into in this thread)

The problem occurs when you pass an extra_param containing certain Unicode
characters. What happens is that the parameter is passed to the signature
creation, and the signature ends up wrong, leading to 401 errors when trying
to make a request.

The fix for this is actually detailed in the above thread, a problem with
the regexp doing the escaping. In Perl's case, the below change
to Net::OAuth's Message.pm fixes this:

sub encode {
   my $str = shift;
   $str =  unless defined $str;
   # return URI::Escape::uri_escape_utf8($str,'^\w.~-');
   # MM, fix based on twitter OAuth bug report
   return URI::Escape::uri_escape($str,'^0-9a-zA-Z\d._~-');
}

I'm not sure if this is relevant to you given your previous messages, but
thought I'd share just in case. With this fix implemented, it seems to work
very well, more than 10,000 of my users have migrated to OAuth and I'm doing
hundreds of thousands OAuth-based status update requests, without obvious
problems.

Mario.


[twitter-dev] Re: OAuth and Perl

2009-04-22 Thread Jesse Stay
Matt, here's what I'm getting back:
On Tue, Apr 21, 2009 at 9:58 AM, Matt Sanford m...@twitter.com wrote:


 Hi Jesse,

The best debugging information is:

 1. The error message from your 401.
   » Example: Failed to validate oauth signature or token


Missing authenticate header




 2. The signature base string. In other words, the string you used to create
 the signature.
  » Example: See [1] for an example.


Any idea how to get this using Perl's Net::OAuth?



 3. What oauth application is this for?
  » Example: http://twitter.com/oauth_clients/details/104


It's for the SocialToo.com application:
http://twitter.com/oauth_clients/details/61




 On Apr 20, 2009, at 07:59 PM, Jesse Stay wrote:

  I'm getting 401 Unauthorized when trying to use Net::OAuth in Perl to
 access Twitter - it's happening in trying to swap the request token for the
 access token (in the second block below, from the $ua-post()).  I was just
 wondering what the best method for debugging this would be.  Here's my code
 (it's in Catalyst, so the $c's are from the Framework environment):

 sub authenticate_twitter : Local {
my ($self, $c) = @_;

unless ($c-user_session-{'request_token'} 
 $c-user_session-{'request_token_secret'}) {
my $request = Net::OAuth-request(request token)-new(
consumer_key = $c-config-{'twitter_consumer_key'},
consumer_secret = $c-config-{'twitter_consumer_secret'},
request_url = $c-config-{'twitter_request_url'},
request_method = 'GET',
signature_method = 'HMAC-SHA1',
timestamp = time,
nonce = join('', rand_chars(size=16, set='alphanumeric')),
);
$request-sign();

$c-log-debug(URL: .$request-to_url);

my $ua = LWP::UserAgent-new;
my $res = $ua-get($request-to_url); # post request to Twitter

if ($res-is_success) {
my $response = Net::OAuth-response('request
 token')-from_post_body($res-content);
$c-user_session-{'request_token'} = $response-token;
$c-user_session-{'request_token_secret'} =
 $response-token_secret;

if (defined $c-user_session-{'request_token'}) {
my $auth_url =
 $c-config-{'twitter_authorize_token_url'}.?oauth_token= .
 $c-user_session-{'request_token'} .
 redirect_url=.uri_escape($c-req-param(redi
 rect_url));;
$c-res-redirect($auth_url);
$c-detach;
return;
}
}
else {
$c-log-fatal(Something went wrong.);
}
}
else {
$c-log-debug(request_token:
 .$c-user_session-{'request_token'});
$c-log-debug(request_token_secret:
 .$c-user_session-{'request_token_secret'});
my $request = Net::OAuth-request(access token)-new(
consumer_key= $c-config-{'twitter_consumer_key'},
consumer_secret = $c-config-{'twitter_consumer_secret'},
token   = $c-user_session-{'request_token'},
token_secret=
 $c-user_session-{'request_token_secret'},
request_url =
 $c-config-{'twitter_access_token_url'},
request_method  = 'POST',
signature_method= 'HMAC-SHA1',
timestamp   = time,
nonce   = join('', rand_chars(size=16,
 set='alphanumeric')),
);
$request-sign();

$c-log-debug(URL: .$request-to_url);

my $ua = LWP::UserAgent-new;
my $res = $ua-post($request-to_url); # post request to Twitter

if ($res-is_success) {
my $response = Net::OAuth-response('access
 token')-from_post_body($res-content);
$c-user_session-{'access_token'} = $response-token;
$c-user_session-{'access_token_secret'} =
 $response-token_secret;


  $c-res-redirect(uri_unescape($c-req-param('redirect_url')));
}
else {
$c-log-fatal(Could not get an Access Token:  .
 $res-status_line .   . $res-content);
}

}

 }

 -...@jesse





[twitter-dev] Re: OAuth and Perl

2009-04-22 Thread Abraham Williams
Not likely. From your error message it looks like you are either not sending
an array of parameters to Net::OAuth or it is dropping them somewhere. I
don't know Perl though so I can't really help any further.

On Wed, Apr 22, 2009 at 18:39, Jesse Stay jesses...@gmail.com wrote:

 Is my issue because OAuth is disabled? Just want to be sure before I look
 into it more (as soon as OAuth is back).
 Thanks,

 Jesse


 On Wed, Apr 22, 2009 at 1:40 AM, Jesse Stay jesses...@gmail.com wrote:

 Matt, here's what I'm getting back:
 On Tue, Apr 21, 2009 at 9:58 AM, Matt Sanford m...@twitter.com wrote:


 Hi Jesse,

The best debugging information is:

 1. The error message from your 401.
   » Example: Failed to validate oauth signature or token


 Missing authenticate header




 2. The signature base string. In other words, the string you used to
 create the signature.
  » Example: See [1] for an example.


 Any idea how to get this using Perl's Net::OAuth?



 3. What oauth application is this for?
  » Example: http://twitter.com/oauth_clients/details/104


 It's for the SocialToo.com application:
 http://twitter.com/oauth_clients/details/61




 On Apr 20, 2009, at 07:59 PM, Jesse Stay wrote:

  I'm getting 401 Unauthorized when trying to use Net::OAuth in Perl to
 access Twitter - it's happening in trying to swap the request token for the
 access token (in the second block below, from the $ua-post()).  I was just
 wondering what the best method for debugging this would be.  Here's my code
 (it's in Catalyst, so the $c's are from the Framework environment):

 sub authenticate_twitter : Local {
my ($self, $c) = @_;

unless ($c-user_session-{'request_token'} 
 $c-user_session-{'request_token_secret'}) {
my $request = Net::OAuth-request(request token)-new(
consumer_key = $c-config-{'twitter_consumer_key'},
consumer_secret = $c-config-{'twitter_consumer_secret'},
request_url = $c-config-{'twitter_request_url'},
request_method = 'GET',
signature_method = 'HMAC-SHA1',
timestamp = time,
nonce = join('', rand_chars(size=16, set='alphanumeric')),
);
$request-sign();

$c-log-debug(URL: .$request-to_url);

my $ua = LWP::UserAgent-new;
my $res = $ua-get($request-to_url); # post request to Twitter

if ($res-is_success) {
my $response = Net::OAuth-response('request
 token')-from_post_body($res-content);
$c-user_session-{'request_token'} = $response-token;
$c-user_session-{'request_token_secret'} =
 $response-token_secret;

if (defined $c-user_session-{'request_token'}) {
my $auth_url =
 $c-config-{'twitter_authorize_token_url'}.?oauth_token= .
 $c-user_session-{'request_token'} .
 redirect_url=.uri_escape($c-req-param(redi
 rect_url));;
$c-res-redirect($auth_url);
$c-detach;
return;
}
}
else {
$c-log-fatal(Something went wrong.);
}
}
else {
$c-log-debug(request_token:
 .$c-user_session-{'request_token'});
$c-log-debug(request_token_secret:
 .$c-user_session-{'request_token_secret'});
my $request = Net::OAuth-request(access token)-new(
consumer_key= $c-config-{'twitter_consumer_key'},
consumer_secret =
 $c-config-{'twitter_consumer_secret'},
token   = $c-user_session-{'request_token'},
token_secret=
 $c-user_session-{'request_token_secret'},
request_url =
 $c-config-{'twitter_access_token_url'},
request_method  = 'POST',
signature_method= 'HMAC-SHA1',
timestamp   = time,
nonce   = join('', rand_chars(size=16,
 set='alphanumeric')),
);
$request-sign();

$c-log-debug(URL: .$request-to_url);

my $ua = LWP::UserAgent-new;
my $res = $ua-post($request-to_url); # post request to Twitter

if ($res-is_success) {
my $response = Net::OAuth-response('access
 token')-from_post_body($res-content);
$c-user_session-{'access_token'} = $response-token;
$c-user_session-{'access_token_secret'} =
 $response-token_secret;


  $c-res-redirect(uri_unescape($c-req-param('redirect_url')));
}
else {
$c-log-fatal(Could not get an Access Token:  .
 $res-status_line .   . $res-content);
}

}

 }

 -...@jesse







-- 
Abraham Williams | http://the.hackerconundrum.com
Hacker | http://abrah.am | http://twitter.com/abraham
Web608 | Community Evangelist | http://web608.org
This email is: [ ] blogable [x] ask first [ ] private.


[twitter-dev] Re: OAuth and Perl

2009-04-21 Thread Matt Sanford


Hi Jesse,

The best debugging information is:

1. The error message from your 401.
   » Example: Failed to validate oauth signature or token

2. The signature base string. In other words, the string you used to  
create the signature.

  » Example: See [1] for an example.

3. What oauth application is this for?
  » Example: http://twitter.com/oauth_clients/details/104

Thanks;
  — Matt Sanford


[1] Example signature base string:

POSThttp%3A%2F
%2F192.168.1.123%3A3000%2Fstatuses%2Fupdate.json
oauth_consumer_key%3Dwritekey%26oauth_nonce 
%3DOzn8q5kDW7rPkFME1P2cN33nlr9i9ESNJmZEmGLUVU

%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp
%3D1239638732%26oauth_token%3D3- 
xzFwdowMs3Rqxv8fKW4zxItwIlsoSN6Vqrnd736r8%26oauth_version%3D1.0
%26status%3Dchecking%2520out%2520matts%2520app 
%2520%2540%25201239638732%2520test%253A%2525C3%2525A6


On Apr 20, 2009, at 07:59 PM, Jesse Stay wrote:

I'm getting 401 Unauthorized when trying to use Net::OAuth in Perl  
to access Twitter - it's happening in trying to swap the request  
token for the access token (in the second block below, from the $ua- 
post()).  I was just wondering what the best method for debugging  
this would be.  Here's my code (it's in Catalyst, so the $c's are  
from the Framework environment):


sub authenticate_twitter : Local {
my ($self, $c) = @_;

unless ($c-user_session-{'request_token'}  $c-user_session- 
{'request_token_secret'}) {

my $request = Net::OAuth-request(request token)-new(
consumer_key = $c-config-{'twitter_consumer_key'},
consumer_secret = $c-config- 
{'twitter_consumer_secret'},

request_url = $c-config-{'twitter_request_url'},
request_method = 'GET',
signature_method = 'HMAC-SHA1',
timestamp = time,
nonce = join('', rand_chars(size=16,  
set='alphanumeric')),

);
$request-sign();

$c-log-debug(URL: .$request-to_url);

my $ua = LWP::UserAgent-new;
my $res = $ua-get($request-to_url); # post request to  
Twitter


if ($res-is_success) {
my $response = Net::OAuth-response('request token')- 
from_post_body($res-content);

$c-user_session-{'request_token'} = $response-token;
$c-user_session-{'request_token_secret'} = $response- 
token_secret;


if (defined $c-user_session-{'request_token'}) {
my $auth_url = $c-config- 
{'twitter_authorize_token_url'}.?oauth_token= . $c-user_session- 
{'request_token'} . redirect_url=.uri_escape($c-req-param(redi

rect_url));;
$c-res-redirect($auth_url);
$c-detach;
return;
}
}
else {
$c-log-fatal(Something went wrong.);
}
}
else {
$c-log-debug(request_token: .$c-user_session- 
{'request_token'});
$c-log-debug(request_token_secret: .$c-user_session- 
{'request_token_secret'});

my $request = Net::OAuth-request(access token)-new(
consumer_key= $c-config- 
{'twitter_consumer_key'},
consumer_secret = $c-config- 
{'twitter_consumer_secret'},
token   = $c-user_session- 
{'request_token'},
token_secret= $c-user_session- 
{'request_token_secret'},
request_url = $c-config- 
{'twitter_access_token_url'},

request_method  = 'POST',
signature_method= 'HMAC-SHA1',
timestamp   = time,
nonce   = join('', rand_chars(size=16,  
set='alphanumeric')),

);
$request-sign();

$c-log-debug(URL: .$request-to_url);

my $ua = LWP::UserAgent-new;
my $res = $ua-post($request-to_url); # post request to  
Twitter


if ($res-is_success) {
my $response = Net::OAuth-response('access token')- 
from_post_body($res-content);

$c-user_session-{'access_token'} = $response-token;
$c-user_session-{'access_token_secret'} = $response- 
token_secret;


$c-res-redirect(uri_unescape($c-req- 
param('redirect_url')));

}
else {
$c-log-fatal(Could not get an Access Token:  . $res- 
status_line .   . $res-content);

}

}

}

-...@jesse