Using Perl and RPC::XML Module
dsdee
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
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
0
Comments
as a reference. It's using a kind of old version of the API by now, but you'll get the idea.
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
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
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
SmugMug API Developer
My Photos
David
SmugMug API Developer
My Photos
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
Does it mean you got changeSettings working????
SmugMug API Developer
My Photos
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
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