semifor / Net-Twitter

A Perl interface to the Twitter APIs
83 stars 37 forks source link

api v1.1 requires https #39

Closed johnfreed closed 9 years ago

johnfreed commented 10 years ago

twitter now blocks the default settings for the module WithAPIv1_1 version 0.12005

specifically, for $Net::Twitter::Lite::WithAPIv1_1::VERSION = '0.12005'

the following need to default to https rather than http ...

sub _default_api_url               () { 'http://api.twitter.com/1.1'    }
sub _default_searchapiurl          () { 'http://search.twitter.com'     }
sub _default_search_trends_api_url () { 'http://api.twitter.com/1.1'    }
sub _default_lists_api_url         () { 'http://api.twitter.com/1.1'    }
goyogi commented 10 years ago

Since Jan14th list_members isn't working. Could you please fix this ASAP ?

Appreciate your support.

johnfreed commented 10 years ago

Yes, a symptom of the same problem. As a workaround you can set the following within the ->new directive:

   apiurl => 'https://api.twitter.com/1.1' ,
   searchapiurl =>  'https://search.twitter.com' ,
   search_trends_api_url =>  'https://api.twitter.com/1.1' ,
   lists_api_url => 'https://api.twitter.com/1.1' ,

Not exactly pretty but works for me

johnfreed commented 10 years ago

ah, I just saw the following in the CPAN docs. FYI, and contrary to the documentation, I received no warning about not passing ssl=>1 to the "new" options. I have tested this solution and it works for me.

The explanation given for not fixing this now, however, makes no sense to me. Rather than doing "ssl=>1" as suggested, it would be fine to simply fix the default URLs (at least those to api.twitter.com), which now always fail. In this sense, the new version is not truly backwards compatible with the old version.

-- here is what CPAN says --

Deprecation cycle. Twitter now requires SSL connections for API calls. To enable SSL, add ( ssl => 1) to the options passed to new. E.g.,

my $nt = Net::Twitter::Lite::WithAPIv1_1->new(
    consumer_key        => $key,
    consumer_secret     => $secret,
    access_token        => $token,
    access_token_secret => $token_secret,
    ssl                 => 1,  ## enable SSL! ##
);

This version will warn if no ssl option is passed to new. For backwards compatibility, the default in this version remains SSL disabled. A future release will change the default to SSL enabled and remove the warning. Add ( ssl => 0 ) to disable the warning and keep SSL disabled.

Why not just make the default SSL enabled, now? Net::Twitter::Lite has always tried to adhere to a strict policy of backwards compatibility. An upgrade to Net::Twitter::Lite should not break or significantly change the behavior of existing code that relies on it. Net::Twitter is used by some for Twitter API compatible services that may or may not require SSL, and for some private test services that require non-SSL connections. They shouldn't break when Net::Twitter::Lite is upgraded. This deprecation cycle is the minimally invasive change that lets user know about Twitter's change without significantly changing the behavior for anyone upgrading.

semifor commented 10 years ago

Did you upgrade to the latest version? ( ssl => 1 ) will work with any version, but only the latest warns.

On Sat, Jan 18, 2014 at 7:15 AM, johnfreed notifications@github.com wrote:

ah, I just saw the following in the CPAN docs. FYI, contrary to the documenation I received no warning about not passing ssl=>1 to the "new" options.

Deprecation cycle. Twitter now requires SSL connections for API calls. To enable SSL, add ( ssl => 1) to the options passed to new. E.g.,

my $nt = Net::Twitter::Lite::WithAPIv1_1->new( consumer_key => $key, consumer_secret => $secret, access_token => $token, access_token_secret => $token_secret, ssl => 1, ## enable SSL! ## );

This version will warn if no ssl option is passed to new. For backwards compatibility, the default in this version remains SSL disabled. A future release will change the default to SSL enabled and remove the warning. Add ( ssl => 0 ) to disable the warning and keep SSL disabled.

Why not just make the default SSL enabled, now? Net::Twitter::Lite has always tried to adhere to a strict policy of backwards compatibility. An upgrade to Net::Twitter::Lite should not break or significantly change the behavior of existing code that relies on it. Net::Twitter is used by some for Twitter API compatible services that may or may not require SSL, and for some private test services that require non-SSL connections. They shouldn't break when Net::Twitter::Lite is upgraded. This deprecation cycle is the minimally invasive change that lets user know about Twitter's change without significantly changing the behavior for anyone upgrading.

— Reply to this email directly or view it on GitHubhttps://github.com/semifor/Net-Twitter/issues/39#issuecomment-32684094 .

johnfreed commented 10 years ago

yes, latest version (0.12005), I believe. Total warnings follow:

HTTP Response Code: 403
HTTP Message......: Forbidden
Twitter error.....: 403: Forbidden
Can't use an undefined value as an ARRAY reference at ./xxx line 70.

This is just for the Lite version. I see in the source that there is a warning in Net::Twitter per se, but I do not have that installed. I don't get a warning in Net::Twitter::Lite

Again, I'd argue that having the default URLs point to http://api.twitter.com rather than https://api.twitter.com is NOT backwards compatible. As is evident by the fact that user programs which used to work now break.

Hmmm ... I see the warning is also in the code for WithAPIv1_1.pm so I'm wondering if somehow I have inadvertently turned off the warning, sigh.

goyogi commented 10 years ago

Johnfreed, thanks for inputs. I added the following, but it's list_members isn't working for me.

I have

apiurl => 'https://api.twitter.com/1.1' , searchapiurl => 'https://search.twitter.com' , search_trends_api_url => 'https://api.twitter.com/1.1' , lists_api_url => 'https://api.twitter.com/1.1' ,

Here is what I have. i have upgraded to latest version of net::twitter.

my $nt = Net::Twitter->new( traits => [qw/API::RESTv1_1/], consumer_key => $consumer_key, consumer_secret => $consumer_secret, access_token => $token, access_token_secret => $token_secret, ssl => 1, apiurl => 'https://api.twitter.com/1.1' , searchapiurl => 'https://search.twitter.com' , search_trends_api_url => 'https://api.twitter.com/1.1' , lists_api_url => 'https://api.twitter.com/1.1' , );

goyogi commented 10 years ago

$result = eval{$nt->list_members({owner_screen_name=>'MyTwitteScreenName',slug=>"My List",cursor=>$cursor})};

$result is undef after this command. It used to work before.

semifor commented 10 years ago

I appreciate your frustration. We disagree an the meaning of backwards compatible. For my part, it means an upgrade to Net::Twitter won't change the behavior of existing code. Twitter made a change that breaks code that does not use SSL connections. Net::Twitter and Net::Twitter::Lite have always allowed SSL connections by simply passing ( ssl => 1 ) in the Net::Twitter or Net::Twitter::Lite constructor. That's all that's necessary to resolve the problem.

The latest release simply adds a warning to ensure users set ( ssl => 0 ) if they need a non-SSL connection, because a future release (in about 90 days), will make ( ssl => 1 ) the default if no ssl option is provided.

Some users have set up proxies and private test servers that intercept port 80 calls to api.twitter.com. If I changed the default URLs to https://api.twitter.com, an upgrade to Net::Twitter (::Lite) would break those programs.

The least disruptive change, in my opinion, was made in the most recent releases of Net::Twitter and Net::Twitter::Lite.

If you'd like to post your code in a gist, with tokens/passwords elided, I'd be happy to take a look and see if I can spot a problem. You're welcome to contact me by email and send a private gist. My email address is in the POD.

On Sat, Jan 18, 2014 at 7:56 AM, johnfreed notifications@github.com wrote:

yes, latest version (0.12005), I believe. Total warnings follow:

HTTP Response Code: 403 HTTP Message......: Forbidden Twitter error.....: 403: Forbidden Can't use an undefined value as an ARRAY reference at ./xxx line 70.

This is just for the Lite version. I see in the source that there is a warning in Net::Twitter per se, but I do not have that installed. I don't get a warning in Net::Twitter::Lite

Again, I'd argue that having the default URLs point to http://api.twitter.com rather than https://api.twitter.com is NOT backwards compatible. As is evident by the fact that user programs which used to work now break.

— Reply to this email directly or view it on GitHubhttps://github.com/semifor/Net-Twitter/issues/39#issuecomment-32685023 .

johnfreed commented 10 years ago

Ah, never mind. I do find upgrades in CPAN a bit frustrating at times, but I just tried this:

print $Net::Twitter::Lite::WithAPIv1_1::VERSION;

and the answer was .12004, not .12005, so I'll try again.

Success -- I now get the warning. No idea why it hadn't upgraded (but only installed) the last time.

I see your point about intercepting calls to port 80.

Thanks for your patience, and for your quick response!

goyogi commented 10 years ago

semifor,

I have SSL enabled,but still not able to get lists_members. Some of the lists related APIs aren't working, Please see my last post about list_members. Appreciate your support here.

Thanks in advance!!

semifor commented 10 years ago

Works for me:

$r = $nt->list_members({ owner_screen_name => 'twitter', slug =>

'official-twitter-accts', cursor => -1 });

Remove the eval. What error do you get? 404? If so, you probably have the owner_screen_name or slug parameters specified incorrectly.

On Sat, Jan 18, 2014 at 1:49 PM, goyogi notifications@github.com wrote:

semifor,

I have SSL enabled,but still not able to get lists_members. Some of the lists related APIs aren't working, Please see my last post about list_members. Appreciate your support here.

Thanks in advance!!

— Reply to this email directly or view it on GitHubhttps://github.com/semifor/Net-Twitter/issues/39#issuecomment-32694181 .

goyogi commented 10 years ago

I don't get any errors!! Trust me, this used to work before. It's not working any more. I don't have slug or screen name wrong. In your case, can your dump $r and see if it's really working ?

goyogi commented 10 years ago

You could try these to see if they work for you:

owner_screen_name: swingTradeAlert Slugs: OtherTraders, WSJandOtherMedia and TopTraders. (These are all public lists).

semifor commented 10 years ago

Works perfectly well for me. I didn't try all the three lists. I assume one is enough:

$r = $nt->list_members({ owner_screen_name => 'SwingTradeAlert', slug

=> 'OtherTraders', cursor => -1 }); say $r->{users}[0]{screen_name};

RatingsNetwork

The response from Twitter should give some clue to the problem. Either remove the eval so it dies with the error message, or test test and warn out $@ immediately after the eval. What error are you getting from Twitter?

On Sat, Jan 18, 2014 at 2:17 PM, goyogi notifications@github.com wrote:

You could try these to see if they work for you:

owner_screen_name: swingTradeAlert Slugs: OtherTraders, WSJandOtherMedia and TopTraders. (These are all public lists).

— Reply to this email directly or view it on GitHubhttps://github.com/semifor/Net-Twitter/issues/39#issuecomment-32694886 .

goyogi commented 10 years ago

Thanks semifor. I did force cpan install of Net:Twitter. Now I am able to get the output. However, something is still broken. The following piece of code, is supposed print twitter users in each of lists. However, I see that after cursor gets assigned a new value, it keeps going in infinite loop. cursor never gets initialized to zero so that loop can be aborted.

Could you please check. Something is definitely broken.

my @TopTradersList = qw(WSJandOtherMedia TopTraders OtherTraders); foreach (@TopTradersList) { my $tradeList = $_; for ( my $cursor = -1, my $result; $cursor; $cursor = $result->{next_cursor} ) { print "$tradeList $cursor\n"; $result = $nt->list_members({owner_screen_name=>'SwingTradeAlert',slug=>$tradeList,$cursor=>"$cursor"});

            #print Dumper $result;

            my $userList = $result->{users};
            foreach (keys @$userList) {
                    my $userId = $$userList[$_]->{id};
                    my $screenName = $$userList[$_]->{screen_name};
                    print "Found :List:$tradeList user:$screenName\n";
            }
            print "New Cursor:$cursor\n";
    }

}

Output: We can see looping here:

pu:workSpace pu$ ./tweetBotDebug.pl WSJandOtherMedia -1 Found :List:WSJandOtherMedia user:GothamResearch Found :List:WSJandOtherMedia user:ReutersTV Found :List:WSJandOtherMedia user:theflynews Found :List:WSJandOtherMedia user:BloombergNow Found :List:WSJandOtherMedia user:emilychangtv Found :List:WSJandOtherMedia user:BW Found :List:WSJandOtherMedia user:Benzinga Found :List:WSJandOtherMedia user:MSN_Money Found :List:WSJandOtherMedia user:BloombergTV Found :List:WSJandOtherMedia user:BloombergNews Found :List:WSJandOtherMedia user:bespokeinvest Found :List:WSJandOtherMedia user:MarketBeat Found :List:WSJandOtherMedia user:WSJLive Found :List:WSJandOtherMedia user:WSJD Found :List:WSJandOtherMedia user:WSJheard Found :List:WSJandOtherMedia user:WSJmarkets Found :List:WSJandOtherMedia user:WSJeconomy Found :List:WSJandOtherMedia user:WSJbusiness Found :List:WSJandOtherMedia user:CNBCnow Found :List:WSJandOtherMedia user:ReutersTech New Cursor:-1 WSJandOtherMedia 4611686018452950174 Found :List:WSJandOtherMedia user:GothamResearch Found :List:WSJandOtherMedia user:ReutersTV Found :List:WSJandOtherMedia user:theflynews Found :List:WSJandOtherMedia user:BloombergNow Found :List:WSJandOtherMedia user:emilychangtv Found :List:WSJandOtherMedia user:BW Found :List:WSJandOtherMedia user:Benzinga Found :List:WSJandOtherMedia user:MSN_Money Found :List:WSJandOtherMedia user:BloombergTV Found :List:WSJandOtherMedia user:BloombergNews Found :List:WSJandOtherMedia user:bespokeinvest Found :List:WSJandOtherMedia user:MarketBeat Found :List:WSJandOtherMedia user:WSJLive Found :List:WSJandOtherMedia user:WSJD Found :List:WSJandOtherMedia user:WSJheard Found :List:WSJandOtherMedia user:WSJmarkets Found :List:WSJandOtherMedia user:WSJeconomy Found :List:WSJandOtherMedia user:WSJbusiness Found :List:WSJandOtherMedia user:CNBCnow Found :List:WSJandOtherMedia user:ReutersTech New Cursor:4611686018452950174 WSJandOtherMedia 4611686018452950174 Found :List:WSJandOtherMedia user:GothamResearch Found :List:WSJandOtherMedia user:ReutersTV Found :List:WSJandOtherMedia user:theflynews Found :List:WSJandOtherMedia user:BloombergNow Found :List:WSJandOtherMedia user:emilychangtv Found :List:WSJandOtherMedia user:BW Found :List:WSJandOtherMedia user:Benzinga Found :List:WSJandOtherMedia user:MSN_Money Found :List:WSJandOtherMedia user:BloombergTV Found :List:WSJandOtherMedia user:BloombergNews Found :List:WSJandOtherMedia user:bespokeinvest Found :List:WSJandOtherMedia user:MarketBeat Found :List:WSJandOtherMedia user:WSJLive Found :List:WSJandOtherMedia user:WSJD Found :List:WSJandOtherMedia user:WSJheard Found :List:WSJandOtherMedia user:WSJmarkets Found :List:WSJandOtherMedia user:WSJeconomy Found :List:WSJandOtherMedia user:WSJbusiness Found :List:WSJandOtherMedia user:CNBCnow Found :List:WSJandOtherMedia user:ReutersTech New Cursor:4611686018452950174 WSJandOtherMedia 4611686018452950174

semifor commented 10 years ago

You want:

    cursor => $cursor

Not:

    $cursor => $cursor

And:

    next_cursor

Not:

    nextcursor

— Sent from Mailbox for iPhone

On Sat, Jan 18, 2014 at 5:27 PM, goyogi notifications@github.com wrote:

Thanks semifor. I did force cpan install of Net:Twitter. Now I am able to get the output. However, something is still broken. The following piece of code, is supposed print twitter users in each of lists. However, I see that after cursor gets assigned a new value, it keeps going in infinite loop. cursor never gets initialized to zero so that loop can be aborted.
Could you please check. Something is definitely broken.
my @TopTradersList = qw(WSJandOtherMedia TopTraders OtherTraders); foreach (@TopTradersList) { my $tradeList = $_;

while ($cursor!=0) ..

    for ( my $cursor = -1, my $result; $cursor; $cursor = $result->{next_cursor} ) {
            print "$tradeList $cursor\n";
            $result = $nt->list_members({owner_screen_name=>'SwingTradeAlert',slug=>$tradeList,$cursor=>"$cursor"});
            #print Dumper $result;
            my $userList = $result->{users};
            foreach (keys @$userList) {
                    my $userId = $$userList[$_]->{id};
                    my $screenName = $$userList[$_]->{screen_name};
                    print "Found :List:$tradeList user:$screenName\n";
            }
            print "New Cursor:$cursor\n";
    }

} Output: We can see looping here: pu:workSpace pu$ ./tweetBotDebug.pl WSJandOtherMedia -1 Found :List:WSJandOtherMedia user:GothamResearch Found :List:WSJandOtherMedia user:ReutersTV Found :List:WSJandOtherMedia user:theflynews Found :List:WSJandOtherMedia user:BloombergNow Found :List:WSJandOtherMedia user:emilychangtv Found :List:WSJandOtherMedia user:BW Found :List:WSJandOtherMedia user:Benzinga Found :List:WSJandOtherMedia user:MSN_Money Found :List:WSJandOtherMedia user:BloombergTV Found :List:WSJandOtherMedia user:BloombergNews Found :List:WSJandOtherMedia user:bespokeinvest Found :List:WSJandOtherMedia user:MarketBeat Found :List:WSJandOtherMedia user:WSJLive Found :List:WSJandOtherMedia user:WSJD Found :List:WSJandOtherMedia user:WSJheard Found :List:WSJandOtherMedia user:WSJmarkets Found :List:WSJandOtherMedia user:WSJeconomy Found :List:WSJandOtherMedia user:WSJbusiness Found :List:WSJandOtherMedia user:CNBCnow Found :List:WSJandOtherMedia user:ReutersTech New Cursor:-1 WSJandOtherMedia 4611686018452950174 Found :List:WSJandOtherMedia user:GothamResearch Found :List:WSJandOtherMedia user:ReutersTV Found :List:WSJandOtherMedia user:theflynews Found :List:WSJandOtherMedia user:BloombergNow Found :List:WSJandOtherMedia user:emilychangtv Found :List:WSJandOtherMedia user:BW Found :List:WSJandOtherMedia user:Benzinga Found :List:WSJandOtherMedia user:MSN_Money Found :List:WSJandOtherMedia user:BloombergTV Found :List:WSJandOtherMedia user:BloombergNews Found :List:WSJandOtherMedia user:bespokeinvest Found :List:WSJandOtherMedia user:MarketBeat Found :List:WSJandOtherMedia user:WSJLive Found :List:WSJandOtherMedia user:WSJD Found :List:WSJandOtherMedia user:WSJheard Found :List:WSJandOtherMedia user:WSJmarkets Found :List:WSJandOtherMedia user:WSJeconomy Found :List:WSJandOtherMedia user:WSJbusiness Found :List:WSJandOtherMedia user:CNBCnow Found :List:WSJandOtherMedia user:ReutersTech New Cursor:4611686018452950174 WSJandOtherMedia 4611686018452950174 Found :List:WSJandOtherMedia user:GothamResearch Found :List:WSJandOtherMedia user:ReutersTV Found :List:WSJandOtherMedia user:theflynews Found :List:WSJandOtherMedia user:BloombergNow Found :List:WSJandOtherMedia user:emilychangtv Found :List:WSJandOtherMedia user:BW Found :List:WSJandOtherMedia user:Benzinga Found :List:WSJandOtherMedia user:MSN_Money Found :List:WSJandOtherMedia user:BloombergTV Found :List:WSJandOtherMedia user:BloombergNews Found :List:WSJandOtherMedia user:bespokeinvest Found :List:WSJandOtherMedia user:MarketBeat Found :List:WSJandOtherMedia user:WSJLive Found :List:WSJandOtherMedia user:WSJD Found :List:WSJandOtherMedia user:WSJheard Found :List:WSJandOtherMedia user:WSJmarkets Found :List:WSJandOtherMedia user:WSJeconomy Found :List:WSJandOtherMedia user:WSJbusiness Found :List:WSJandOtherMedia user:CNBCnow Found :List:WSJandOtherMedia user:ReutersTech New Cursor:4611686018452950174

WSJandOtherMedia 4611686018452950174

Reply to this email directly or view it on GitHub: https://github.com/semifor/Net-Twitter/issues/39#issuecomment-32698584

goyogi commented 10 years ago

semifor, thanks!! Finally it's working.. It was next_cursor. Not when I edit the post, it shows as next_cursor, but not sure why it shows on page as nextcursor not next_cursor!! However, the bug was $cursor=>$cursor. When I switched to cursor=>"$cursor" it started working. Looking like I had the bug all along. Not sure why it worked before and kinda stopped working now!!

thanks a bunch for your time. Appreciate your support here!!