View Full Version : Using Perl and RPC::XML Module
dsdee
Apr-13-2005, 11:43 AM
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
rutt
Apr-13-2005, 12:13 PM
I had great luck with python doing this. You might want to look at the code in sm_tool.py (http://gate.chezrutt.com:8030/rutt/sm_tool/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.
dsdee
Apr-13-2005, 12:15 PM
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
onethumb
Apr-13-2005, 02:24 PM
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
dsdee
Apr-13-2005, 04:48 PM
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
Bad example, cause smugmug.albums.changeSettings doesn't actually work.
devbobo
Apr-13-2005, 05:05 PM
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
devbobo
Apr-13-2005, 05:07 PM
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
onethumb
Apr-13-2005, 05:48 PM
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
Nikolai
Apr-13-2005, 06:23 PM
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????
devbobo
Apr-13-2005, 06:45 PM
Does it mean you got changeSettings working????
Nope http://dgrin.com/images/smilies/headscratch.gif
Nope http://dgrin.com/images/smilies/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
onethumb
May-23-2005, 05:03 PM
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
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
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.