I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-11-15 09:24:34.208698-08 by zhe
Why my search result is undef?
I am using the following code to search. But get a output "undef". Can anyone help me to fix it?
use Net::Twitter; use Data::Dumper; my $nt = Net::Twitter->new(traits => [qw/API::Search WrapError/]); my $search_term = 'twitter'; my $r = $nt->search($search_term); print Dumper $r;
Direct Responses: 13062 | Write a response
Posted on 2010-11-15 09:47:30.121358-08 by semifor in response to 13061
Re: Why my search result is undef?

When using WrapError, if an error occurs, Net::Twitter returns undef. See perldoc Net::Twitter::Role::WrapError for details on how to extract information about the error.

The following code works for me:

#!/usr/bin/env perl use warnings; use strict; use Net::Twitter; use Data::Dumper; my $nt = Net::Twitter->new(traits => [qw/API::Search WrapError/]); my $search_term = 'twitter'; if ( my $r = $nt->search($search_term) ) { print Dumper $r; } else { # when $r is undefined, an error occurred # See perldoc Net::Twitter::Role::WrapError print $nt->http_response->as_string; }
Direct Responses: 13063 | Write a response
Posted on 2010-11-15 10:46:09.687687-08 by zhe in response to 13062
Re: Why my search result is undef?
When I use your code, I get an error. Can't locate object method "http_response" via package "Net::Twitter::with__API_Search__WrapError" Dose it mean that I did not get my packages installed correctly? Thanks
Direct Responses: 13064 | Write a response
Posted on 2010-11-15 10:51:55.340499-08 by semifor in response to 13063
Re: Why my search result is undef?
It means I failed to read my own documentation. It should be http_message, not http_response. $nt->get_error will extract just the error message out of the response. $http_message->as_string should show you the entire response including headers, etc.
Direct Responses: 13066 | Write a response
Posted on 2010-11-15 12:40:45.335414-08 by zhe in response to 13064
Re: Why my search result is undef?
Now I get Can't locate object method "as_string" via package "Use Proxy Server" (perhaps you forgot to load "Use Proxy Server"?) Thanks for your patient. I am new to this.
Direct Responses: 13067 | Write a response
Posted on 2010-11-15 12:57:11.911745-08 by semifor in response to 13066
Re: Why my search result is undef?
To print the entire request: print $nt->_http_response->as_string; To print the error message (which may come from Twitter or may be generated locally if the LWP::UserAgent can't make a connection to Twitter): print $nt->http_message To print just the error code (500, 502,503, 401, etc.): print $nt->http_code Sorry I confused the issue.
Direct Responses: 13068 | Write a response
Posted on 2010-11-15 13:08:09.729436-08 by zhe in response to 13067
Re: Why my search result is undef?
I get an 403 error, use Proxy Server. Can I do sth in the code to avoid using proxy server, or I have to ask my network administrator to change the settings?
Direct Responses: 13069 | Write a response
Posted on 2010-11-15 13:49:00.104208-08 by semifor in response to 13068
Re: Why my search result is undef?
If I understand the problem correctly, you're behind a firewall and the 403 you're getting is generated internally. You may be able resolve the problem by specifying the proxy server address in the environment. In the perl code, before the Net::Twitter->new call, add: $ENV{HTTP_PROXY} = $proxy_address; Where $proxy_address is the ip address of your proxy server. You can contact me directly via email: marc <at> questright.com.
Direct Responses: Write a response