Subject: | Reading friends comments - broken |
When logging in and viewing friends' comments on their pages, it seems
to fail to do so.
This was working a couple of months ago. Please review the following
code and output:
CODE:
--snip--
#!/opt/local/bin/perl
#
use strict;
use warnings;
use WWW::Myspace;
$| = 1;
my $username = $ARGV[0];
my $password = $ARGV[1];
my @friends;
print "Username: $username\tPassword: $password\n";
print "Logging in... ";
my $myspace = WWW::Myspace->new( $username, $password );
print "done\n";
if ( ! $myspace->logged_in ) {
print "Unable to login: " . $myspace->error . "\n";
}
# Get list of your friends
print "Getting friends... ";
@friends = $myspace->get_friends();
print "done\n";
my %friend_mapping; # key = id, value = name
# Present list all nice-like
foreach my $friend (@friends) {
eval {
print "friend id.: $friend\n";
my $friend_name = $myspace->friend_user_name($friend);
print "name......: $friend_name\n";
$friend_mapping{$friend} = $friend_name;
print "Getting last 5 comments.\n";
my $comments = $myspace->get_comments($friend);
my $max_comments_display = 5;
while ($max_comments_display > 0 && $comments) {
my $comment = shift @{$comments};
my $friend_name_comment = "";
if (!$comment) {
print "- Unable to get comment\n";
} else {
if ($comment && exists $comment->{sender} && exists
$friend_mapping{$comment->{sender}}) {
$friend_name_comment = $friend_mapping{$comment-
Show quoted text
>{sender}};
} else {
eval { $friend_name_comment = $myspace-
Show quoted text>friend_user_name($comment->{sender})};
if ($friend_name_comment) {
$friend_mapping{$comment->{sender}} =
$friend_name_comment;
}
}
if ($friend_name_comment) {
print "- $friend_name_comment ($comment->{sender}) @
$comment->{date}, $comment->{time}\n$comment->{comment}\n\n";
} else {
print "- N/A ($comment->{sender}) @ $comment->{date}\n";
}
}
$max_comments_display--;
}
};
if ($@) {
print "Unable to complete request: $@\n";
}
}
--snip--
SAMPLE OUTPUT (please excuse the comments, only showing to prove it
works for myself yet not for others):
--snip--
christopherhumphries:~/Projects/Testing/Perl-WWW-Myspace-Examples$ /opt/
local/bin/perl getFriendComments.pl yyyyyyyyyyyyy xxxxxxxxxxxx
Username: yyyyyyyyyyyyy Password: xxxxxxxxxxxx
Logging in... done
Getting friends... done
friend id.: 210005732
name......: unixfudotnet
Getting last 5 comments.
- Kelly (285892570) @ Nov 27, 2007 5:52 PM, 1196203920
Thanks, bandwagon jumper =P
- Kelly (285892570) @ Nov 27, 2007 5:45 PM, 1196203500
You're gay
- MeTh (1637787) @ Nov 27, 2007 12:31 PM, 1196184660
thank you for the flowers... there really beautiful and a nice lunch
time snack for my fat ass cat :o)
- MeTh (1637787) @ Nov 27, 2007 1:13 AM, 1196143980
:::::looks all innocent::::::::
- MeTh (1637787) @ Nov 25, 2007 12:07 PM, 1196010420
umm yea..... do over? lol .. i had a good time and i think if i had to
pee, i would of pee'd myself laughing... ill tyyl beebeee
friend id.: 25913110
name......: queen of the metaverse
Getting last 5 comments.
- Unable to get comment
- Unable to get comment
- Unable to get comment
- Unable to get comment
- Unable to get comment
friend id.: 101527072
name......: Saverio
Getting last 5 comments.
- Unable to get comment
- Unable to get comment
- Unable to get comment
- Unable to get comment
- Unable to get comment
--snip--
This same code worked a couple of months ago. Was part of the
WWW::Myspace article I wrote at http://perlandmac.blogspot.com/2007/08/
using-perl-wwwmyspace.html that doesn't work now.
Please let me know if this is a fault in my code or your code.
Thanks!