Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Twitter API - Not a hash reference

by Anonymous Monk
on Mar 08, 2018 at 20:13 UTC ( #1210528=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Documentation: Net::Twitter

My goal is to have it return the lates status & screen name of the user searched for. I'm pretty confused by hash references, as when I use the dumper I just see this=>that=>this, but I can't figure out how to access all these things that I want.

But looking at the documentation for "lookup_users", it gives an array first, maybe since you can search multiple things, I think I figured out how to access that, but after that I'm not sure.

use warnings; use 5.010; use Net::Twitter; use Config::Tiny; use Data::Dumper qw(Dumper); use File::HomeDir; use Data::Dumper; my $nt = Net::Twitter->new( ssl => 1, traits => [qw/API::RESTv1_1/], consumer_key => '', consumer_secret => '', access_token => '', access_token_secret => '', ); my $l = $nt->lookup_users({ screen_name => 'twitter'}); my $tweet = (@{$l->{screen_name}}); print "$tweet\n";

Here I just tried to grab the screen name for a start, since the "status" is deeper. But this just gives me "Not a HASH reference"

Replies are listed 'Best First'.
Re: Twitter API - Not a hash reference
by Discipulus (Monsignor) on Mar 08, 2018 at 20:25 UTC

    Just seeing docs (never twitted inmy life..) I assume $nt->lookup_users.. returns an array so you need to iterate over element or access directly one as in:

    # totally untested! my @users = $nt->lookup_users; foreach my $usr (@users){ print $usr{screen_name}; #?? use Data:Dump dd method to see the structure you get back (better t +han Data::Dumper) dd $usr } # or directly first element returned print $users[0]{screen_name}; dd $users[0];

    I just looked here and here

    UPDATE sorry the method does not returns an array but an array ref: not big difference but different..

    # totally untested! again my $users = $nt->lookup_users; foreach my $usr (@$users){ print $usr{screen_name}; #?? use Data:Dump dd method to see the structure you get back (better t +han Data::Dumper) dd $usr } # or directly first element returned print $$users[0]->{screen_name}; dd $$users[0];


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      This works, thanks! And Data::Dump help me figure out how get to the latest tweet also :) Very helpful.
Re: Twitter API - Not a hash reference
by stevieb (Abbot) on Mar 08, 2018 at 20:24 UTC

    Please edit your question with the actual data structure coming back after being rendered through Data::Dumper.

    We can then help you understand how to extract the bits you want.

        He don't have no Doctor Robert
        He don't have no Uncle Albert
        He don't even have good credit
        He can write, but he can't edit

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1210528]
Approved by Discipulus
[Corion]: marto: Hmm - that's an interesting idea, looking at the VBI data, but I would expect my input to come over IP :)
[Corion]: Random googling showed me CommercialDetectio n, which discusses several approaches and seems to settle on the audio...
[LanX]: no big help, tv is slaughtering many movies in ways which are not fixable
[Corion]: But maybe I should try the idea of audio fingerprinting there, just to automatically annotate radio broadcasts I record... These don't have playlist information integrated as they are raw mp3 streams (no icecast)...
[marto]: also, if your steam has the subtitle data, I that's fairly easily parsable

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2018-05-24 11:29 GMT
Find Nodes?
    Voting Booth?