Using Perl and RPC::XML Module

dsdeedsdee Registered Users Posts: 23 Big grins
Has anyone (successfully) used Perl and the RPC::XML::Client CPAN Module to communicate with Smugmug ??

I've had partial success with the calls; if I specify each parameter value without naming it (ie, a login with just "email, password, version, APIKey") I can get a successful login. But If I try doing named-value pairs, such as the example below, I cannot login.

Sample:



<code>
$req = RPC::XML::request->new("smugmug.login.withPassword",
RPC::XML::struct->new(
'emailAddress' => RPC::XML::string->new($userEmail),
</code><code> </code><code> 'password' => RPC::XML::string->new($pw),
</code><code> </code><code> 'version' => RPC::XML::string->new($smVersion),
</code><code> </code><code> 'APIKey' => RPC::XML::string->new($APIKey)
)
);
</code>

Anyone else tried this?

Thanks,
David

Comments

  • ruttrutt Registered Users Posts: 6,511 Major grins
    edited April 13, 2005
    I had great luck with python doing this. You might want to look at the code in sm_tool.py
    as a reference. It's using a kind of old version of the API by now, but you'll get the idea.
    If not now, when?
  • dsdeedsdee Registered Users Posts: 23 Big grins
    edited April 13, 2005
    parameters and stuff..
    Yeah I had looked at it already, thanks!!

    I want to keep it in Perl as I know it better.
    I'd be fine for just using the parameters in order without naming them, but I want to be able to not-use the optional parameters on some of the rpc calls by not specifying them, and just make the calls shorter.

    With all the (other) geeks around here, someone else has had to have done this before me!!

    --david
  • onethumbonethumb Administrators Posts: 1,269 Major grins
    edited April 13, 2005
    dsdee wrote:
    Yeah I had looked at it already, thanks!!

    I want to keep it in Perl as I know it better.
    I'd be fine for just using the parameters in order without naming them, but I want to be able to not-use the optional parameters on some of the rpc calls by not specifying them, and just make the calls shorter.

    With all the (other) geeks around here, someone else has had to have done this before me!!

    --david

    AFAICT, the XML-RPC spec only allows named values within structs. It's probably my least favorite thing about XML-RPC.

    Since the methods don't expect a struct, I'll bet the CPAN module is constructing a struct with the name=value pairs and sending them, which I can't parse.

    Send them without names in the proper order, and I think it'll work. I'll look into extending the API to work with more complicated struct submission rather than straight values.

    Don
  • dsdeedsdee Registered Users Posts: 23 Big grins
    edited April 13, 2005
    onethumb wrote:
    AFAICT, the XML-RPC spec only allows named values within structs. It's probably my least favorite thing about XML-RPC.

    Since the methods don't expect a struct, I'll bet the CPAN module is constructing a struct with the name=value pairs and sending them, which I can't parse.

    Send them without names in the proper order, and I think it'll work. I'll look into extending the API to work with more complicated struct submission rather than straight values.

    Don
    Don, true, it did work. But then my question arose from the specification of smugmug.albums.changeSettings which statesxx xx

    Arguments:
    • String SessionID
    • int AlbumID
    • struct: [optional, any or none of these can be present]
    • ....
    so is that 'struct' statement, then, not so true?? If so, then how can I specify a parameter without specifying values for all the intermediate values??

    Thanks in advance,
    David
  • jefjef Registered Users Posts: 42 Big grins
    edited April 13, 2005
    Bad example, cause smugmug.albums.changeSettings doesn't actually work.
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited April 13, 2005
    onethumb wrote:
    AFAICT, the XML-RPC spec only allows named values within structs. It's probably my least favorite thing about XML-RPC.

    Since the methods don't expect a struct, I'll bet the CPAN module is constructing a struct with the name=value pairs and sending them, which I can't parse.

    Send them without names in the proper order, and I think it'll work. I'll look into extending the API to work with more complicated struct submission rather than straight values.

    Don
    Don,

    Could this be why I am having problems with smugmug.albums.changeSettings, I create a struct with the optional parameters, then call the method like this...

    'changeAlbumSettings', [objSessionID, objAlbumID, objStruct], 3

    are you expecting individual parameters or a struct ?

    Thanks,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited April 13, 2005
    devbobo wrote:
    Don,

    Could this be why I am having problems with smugmug.albums.changeSettings, I create a struct with the optional parameters, then call the method like this...

    'changeAlbumSettings', [objSessionID, objAlbumID, objStruct], 3

    are you expecting individual parameters or a struct ?

    Thanks,

    David
    Actually forget that, cuz smugmug.albums.create works fine when a struct is passed with the optional parameters.

    David
    David Parry
    SmugMug API Developer
    My Photos
  • onethumbonethumb Administrators Posts: 1,269 Major grins
    edited April 13, 2005
    dsdee wrote:
    Don, true, it did work. But then my question arose from the specification of smugmug.albums.changeSettings which statesxx xx

    Arguments:
    • String SessionID
    • int AlbumID
    • struct: [optional, any or none of these can be present]
    • ....
    so is that 'struct' statement, then, not so true?? If so, then how can I specify a parameter without specifying values for all the intermediate values??

    Thanks in advance,
    David

    It means that the 3rd option should be a struct, which contains name=value pairs for all the optional parameters.

    The first two should be un-named.

    Don
  • NikolaiNikolai Registered Users Posts: 19,035 Major grins
    edited April 13, 2005
    David,
    devbobo wrote:
    Actually forget that, cuz smugmug.albums.create works fine when a struct is passed with the optional parameters.

    David
    Does it mean you got changeSettings working????
    "May the f/stop be with you!"
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited April 13, 2005
    Nikolai wrote:
    Does it mean you got changeSettings working????
    Nope headscratch.gif
    David Parry
    SmugMug API Developer
    My Photos
  • sibsib Registered Users Posts: 16 Big grins
    edited May 22, 2005
    Same problem here...
    devbobo wrote:
    Nope headscratch.gif
    I've been trying the same thing. The interesting thing is that I can do an anonymous login using the parameter names
    <code>
    $req = RPC::XML::request->new('smugmug.login.anonymously',
    Version => '1.1.0',
    APIKey => '< my api key >');
    </code>
    and it works fine, returning a SessionID, whereas if I try it the same way with the email / password I get "invalid login".
    <code>
    my $req = RPC::XML::request->new('smugmug.login.withPassword',
    EmailAddress => '< my email >',
    Password => '< my password >',
    Version => '1.1.0',
    APIKey => '< my api key >');</code>

    (And it's not a email / pw mismatch, because if I just remove the field names but leave the email and pw the same, like below, I get a successful login.)
    <code>
    my $req = RPC::XML::request->new('smugmug.login.withPassword',
    '< my email >',
    '< my password >',
    '1.1.0',
    '< my api key >');
    </code>
    Anyone have thoughts on this? I'd rather not rely on parameter ordering unless absolutely necessary, as I find it leads to unmaintainable code...

    Thanks,

    Scott
  • onethumbonethumb Administrators Posts: 1,269 Major grins
    edited May 23, 2005
    sib wrote:
    I've been trying the same thing. The interesting thing is that I can do an anonymous login using the parameter names
    <code>
    $req = RPC::XML::request->new('smugmug.login.anonymously',
    Version => '1.1.0',
    APIKey => '< my api key >');
    </code>
    and it works fine, returning a SessionID, whereas if I try it the same way with the email / password I get "invalid login".
    <code>
    my $req = RPC::XML::request->new('smugmug.login.withPassword',
    EmailAddress => '< my email >',
    Password => '< my password >',
    Version => '1.1.0',
    APIKey => '< my api key >');</code>

    (And it's not a email / pw mismatch, because if I just remove the field names but leave the email and pw the same, like below, I get a successful login.)
    <code>
    my $req = RPC::XML::request->new('smugmug.login.withPassword',
    '< my email >',
    '< my password >',
    '1.1.0',
    '< my api key >');
    </code>
    Anyone have thoughts on this? I'd rather not rely on parameter ordering unless absolutely necessary, as I find it leads to unmaintainable code...

    Thanks,

    Scott

    As noted in the Beta thread, the new API supports structs of name/value pairs for all the calls. At least, it does theoretically - testing is needed. :)

    Don
  • sibsib Registered Users Posts: 16 Big grins
    edited May 24, 2005
    Cool...
    onethumb wrote:
    As noted in the Beta thread, the new API supports structs of name/value pairs for all the calls. At least, it does theoretically - testing is needed. :)

    Don
    Ahh, excellent, thanks. Now that I've gotten my app working using the existing API, I'll work on finding some time to convert it to the Beta API.

    Scott
Sign In or Register to comment.