Subject: | Myspace::Comment Sample Code Doesn't Seem to Work |
The following code--based heavily on the sample code in the
docs--produces a $response output of "0". I've verified that the
$newComment scalar is populated with the content of my text file. Also,
in your sample code, it looks like the 24 hour sleep statement is in the
wrong place...shouldn't it be contained within the if clause? (why is
the sleep statement needed if you can set a delay_time option? seems
like it would sleep automatically with appropriate output from Myspace...)
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use WWW::Myspace;
use WWW::Myspace::Comment;
my $username = 'edited'; # string
my $password = 'edited'; # string
my $cacheDir = $ENV{'HOME'} . "/.www-myspace"; # string
default is "$ENV{'HOME'}/.www-myspace"
my $cacheFile = 'login_cache'; # string
default is "login_cache"
my $autoLoginToggle = '1'; # [0|1]
default is "1"
my $commentCache = 'commented'; # string
default is "commented"
my $ignoreDuplicatesToggle = '1'; # [0|1]
default is "0"
my $maxRequests = '50'; # integer
default is "50"
my $htmlToggle = '0'; # [0|1]
default is "0"
my $sleepTime = '43200'; # integer
default is "86400"
my $noisyToggle = '0'; # [0|1]
default is "0"
#my $interactiveToggle = '1'; # [0|1]
default is "1"
my $newCommentFile = 'myComment.txt';
my $newComment;
##########
# do not edit below this line
##########
# grab user-defined variables
my %myspace_params = (
account_name => $username,
password => $password,
cache_dir => $cacheDir,
cache_file => $cacheFile,
auto_login => $autoLoginToggle
);
# create the cache directory if it doesn't already exist
unless (-e $cacheDir) {
my $tempspace = WWW::Myspace->new(
\%myspace_params,
);
print ( "Comment cache directory does not exist. Creating in
selected location ... " );
$tempspace->make_cache_dir;
print ( "Succeeded.\n" );
}
# establish connection to your Myspace account
my $myspace = WWW::Myspace->new(
\%myspace_params,
);
my $comment = WWW::Myspace::Comment->new( $myspace );
my $response = "";
$comment->cache_file ( $commentCache );
$comment->max_count ( $maxRequests );
$comment->html ( $htmlToggle );
$comment->noisy ( $noisyToggle );
$comment->delay_time ( $sleepTime );
#$comment->interactive( $interactiveToggle );
$comment->ignore_duplicates( $ignoreDuplicatesToggle ); # we're
sending a message, no worries if we've posted
open ( COMMENT, $newCommentFile) or die ( "Comment file $newCommentFile
is not found or could not be opened for read access.\t $!\n" );
while ( my $line = <COMMENT> ) {
$newComment = $line;
$newComment =~ s/(\r\n?|\n)//g; # clean
up the extra line endings
print ( $newComment );
}
close COMMENT;
# !!DEBUG!! probably a good something to try when troubleshooting
print ( "$newComment\n" );
# Post our comment until we're done - may take several days if we're popular
while ( $response ne "DONE" ) {
$response = $comment->post_comments( $newComment );
# !!DEBUG!! probably a good something to try when troubleshooting
print ( "$response\n" );
if ( $response eq "CAPTCHA" ) {
#[ do nothing, or get the form, post it yourself, and
continue ]
#( Hint: the page is in $myspace->{current_page}->content )
# (If response is CAPTCHA or COUNTER, we wait then continue
# until we're done). Note that you can probably sleep
for 12 hours
# instead of 24.
sleep 12*60*60;
}
}
# We're done sending this message - reset the exclusions file
# completely.
$comment->reset_exclusions('all');