Options

Problem with perl wrapper?

arjunrcarjunrc Registered Users Posts: 159 Major grins
Hi, I am getting my feet wet with the perl wrapper for Smugmug.
It's logging in fine, but when I Try and print my albums its empty. I have one album called 'World' - why is it not showing up?
print "Logging into Smugmug";
my $sm_api = WWW::SmugMug::API->new(
        {
            sm_api_key => $mykey,
            secure     => 1,
        }
    );

$rv=$sm_api->login_withPassword(
        {
            EmailAddress => 'my@email.com',
            Password     => 'mypassword',
        }
    );
    
print "Login result is ", $rv->{'stat'},"\n";
my $albums = $sm_api->albums_get();
foreach my $album (@{$albums->{'Albums'}}) {
	$title=$album->{'title'};
	print $title;
}

The output is:
Logging into SmugmugLogin result is ok

Comments

  • Options
    arjunrcarjunrc Registered Users Posts: 159 Major grins
    edited July 8, 2012
    Ok, I did some more investigation. The 'stat' result for login is ok, but for the album_get, it returns 'Invalid API key'. The Key is exactly what I got from smugmug - I got two strings, a key and a secret. I am using the key - I don't see a provision to enter the secret in the perl APIs.
    How come login worked then?

    Also, I found and older thread where someone posted you need to associate a cookie file to it. I know how to associate it to a user agent (LWP), but how do you connect it to $sm_api variable? Sorry, my knowledge of perl is very basic :-)
  • Options
    arjunrcarjunrc Registered Users Posts: 159 Major grins
    edited July 8, 2012
    Ok, solved. I took at look at the code of WWW::Smugmug::API

    To link it to a cookies file, you need to use the ua element of sm_api_key like so. This may help other folks using perl:
    my $cj=HTTP::Cookies->new(
        file => "sm_cookies.dat",
        autosave => 1,
      );
    
    print "Logging into Smugmug";
    my $sm_api = WWW::SmugMug::API->new(
            {
                sm_api_key => $mykey,
                secure     => 1,
            }
        );
    
    $sm_api->{ua}->cookie_jar($cj);
    
Sign In or Register to comment.