in reply to Re^3: Running JavaScript from within Perl (or just use the API)
in thread Running JavaScript from within Perl
There is no element named "meta.links.self" in the returned JSON, so when you try to set $feedurl to that it is unititialised.
Also, you call $ua->get($url)->result->json twice in the space of 3 lines. DRY.
use strict; use warnings; use Mojo::UserAgent; use Data::Dumper; my $url = 'https://public-api.wordpress.com/rest/v1/read/feed/34259929 +'; my $ua = Mojo::UserAgent->new; my $json = $ua->get($url)->res->json; print Dumper ($json); my $subscribers = $json->{subscribers_count}; print "\nNumber of subscribers: $subscribers\n"; my $feedurl = $json->{meta}{links}{self}; print "URL is $feedurl\n";
This works for me. My version of Mojo::UserAgent (Mojolicious 5.77) does not have a result method. YMMV.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Running JavaScript from within Perl (or just use the API)
by anautismobserver (Sexton) on Sep 23, 2019 at 19:11 UTC | |
by haukex (Archbishop) on Sep 23, 2019 at 22:44 UTC | |
by anautismobserver (Sexton) on Sep 24, 2019 at 17:16 UTC | |
by marto (Cardinal) on Sep 24, 2019 at 18:35 UTC |