Skip to content

Instantly share code, notes, and snippets.

@yupe
Created March 12, 2012 11:10
Show Gist options
  • Save yupe/2021239 to your computer and use it in GitHub Desktop.
Save yupe/2021239 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use 5.010;
use Data::Dumper;
use Mojo::UserAgent;
use Mojo::JSON;
my $user = 'xomaa';
my $url = "https://api.twitter.com/1/favorites.json?count=3&include_entities=1&id=$user";
my $ua = Mojo::UserAgent->new;
my $result = $ua->get($url)->res->json;
foreach my $tweet (@$result) {
say 'Text is => ',$tweet->{text};
say 'Id is => ',$tweet->{id};
#обработка ссылок из твита
if(exists $tweet->{entities}->{urls} && ref $tweet->{entities}->{urls} eq 'ARRAY') {
#доп проверка - проходит на УРА!
if(ref $tweet->{entities}->{urls} eq 'ARRAY') {
# печатает "ARRAY"
say ref $tweet->{entities}->{urls};
# в этом цикле вылетает с "Not an ARRAY reference at file.pl line 23"
foreach my $link (@$tweet->{entities}->{urls}){
say $link->{expanded_url};
}
}
}
say "==========================\n";
}
@yupe
Copy link
Author

yupe commented Mar 12, 2012

Попробуйте запустить у себя, или туплю где-то или я не знаю уже что и делать =)

@yupe
Copy link
Author

yupe commented Mar 12, 2012

Самое интересное, что проверка "ref $tweet->{entities}->{urls} eq 'ARRAY'" проходит, а на цикле отваливается =(

@yupe
Copy link
Author

yupe commented Mar 12, 2012

Если перед циклом добавить "say ref $tweet->{entities}->{urls};", выведет "ARRAY" =)

@yupe
Copy link
Author

yupe commented Mar 12, 2012

Решено вот так foreach my $link (@{$tweet->{entities}->{urls}}){

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment