Flickr-Upload
view release on metacpan or search on metacpan
flickr_upload view on Meta::CPAN
my $key = shift;
my $token = shift;
my $res = $ua->execute_method("flickr.auth.checkToken",
{
'auth_token' => $token,
'api_key' => $key,
} );
# FIXME: this could be parsed, but I'm not going to get too fancy
print $res->decoded_content();
return 0;
}
__END__
=head1 NAME
flickr_upload - Upload photos to C<flickr.com>
lib/Flickr/Upload.pm view on Meta::CPAN
# to die on large uploads due to some miscellaneous network
# issues. Timeouts on flickr or something else.
my ($res, $xml);
my $tries = 3;
for my $try (1 .. $tries) {
# Try to upload
$res = $self->request( $req );
return () unless defined $res;
if ($res->is_success) {
$xml = XMLin($res->decoded_content, KeyAttr=>[], ForceArray=>0);
return () unless defined $xml;
last;
} else {
my $what_next = ($try == $tries ? "giving up" : "trying again");
my $status = $res->status_line;
print STDERR "Failed uploading attempt attempt $try/$tries, $what_next. Message from server was: '$status'\n";
next;
}
}
my $photoid = $xml->{photoid};
my $ticketid = $xml->{ticketid};
unless( defined $photoid or defined $ticketid ) {
print STDERR "upload failed:\n", $res->decoded_content(), "\n";
return undef;
}
return (defined $photoid) ? $photoid : $ticketid;
}
=head2 file_length_in_encoded_chunk
$HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;
my $photo = 'image.jpeg';
lib/Flickr/Upload.pm view on Meta::CPAN
my $res = $self->execute_method( 'flickr.photosets.create',
{ 'title' => $title,
'description' => $description,
'primary_photo_id' => $primary_photo_id,
'auth_token' => $auth_token,
} ) ;
#TODO: Add detailed error messages
return undef unless defined $res and $res->{success};
my $hash = XMLin($res->decoded_content(), KeyAttr=>[], ForceArray=>0);
my $photoset_id = $hash->{photoset}->{id};
if ( ! defined $photoset_id ) {
warn "Failed to extract photoset ID from response:\n" .
$res->decoded_content() . "\n\n";
return undef;
}
return $photoset_id ;
}
=head2 photosets_addphoto
Calls Flickr's "flickr.photosets.addPhoto" method,
to add a (existing) photo to an existing set.
( run in 0.560 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )