trying to use RemoteProtocol from php

rgr

Joined: 2007-05-22
Posts: 5
Posted: Tue, 2007-05-22 11:49

I am bloddy new to gallery, but I try to implement a simple client which uses the RemoteProtocol. I like to use php. But I got stuck with the authentification.

Code-Snipet:

require_once("HTTP/Request.php");
datafields= array(
"g2_form[cmd]"=>"login",
"g2_form[protocol_version]"=>"2.0",
"g2_form[uname]"=>"admin",
"g2_form[password]"=>"password"
);
$param=array(
method => "POST"
);

$connection = &new HTTP_Request($url,$param);
foreach ($datafields as $key=>$value) {
$connection->addPostData($key, $value);
}
$connection->sendRequest();
$return= $connection->getResponseBody();

$return=explode("\n",$return);
foreach($return as $line) {
echo "$line\n";
$fields=explode("=",$line);
// print_r($fields);
if ($fields[0] == "auth_token") {
$authToken=$fields[1];
}
} // foreach
$datafields=array(
"g2_form[cmd]"=>"fetch-albums-prune",
"g2_form[protocol_version]"=>"2.0",
"g2_form[no_perms]"=>"no",
"g2_form[g2_authToken]"=>"$authToken",
"g2_form[authToken]"=>"$authToken",
"g2_authToken" => "$authToken",
"authToken" => "$authToken"
);
echo "authToken:$authToken\n";
foreach ($datafields as $key=>$value) {
$connection->addPostData($key, $value);
}
$connection->addQueryString("g2_authToken","$authToken");
$connection->sendRequest();
echo "\n-----\n".$return= $connection->getResponseBody();

As far as I understood, this should login and then give me the list of albumbs the admin is allowed to write to (which are all)
But the output is the following:

#__GR2PROTO__
server_version=2.11
debug_core_version=7,18
debug_module_version=1.0.9
status=0
status_text=Login successful.
debug_user=admin
debug_time=0,107s
auth_token=cc039186fad7
authToken:cc039186fad7

-----
#__GR2PROTO__
debug_time_albumids=0,038s
status=0
album_count=0
status_text=No viewable albums.
debug_user=guest
debug_time=0,038s

Obviously there is something wrong with the authentification,
You will notice, that I inserted the authToken in different Variables (GET/POST, in and outside of the form), but nothing works.

Could someone tell me what goes wrong there?

Any help, including links to manuals appreciated. Also code snipets of course.
If this is the wrong forum tell me, I will move..

System:
Gallery-Version = 2.2.1 Kern 1.2.0.1
PHP-Version = 4.4.4-8+etch2 apache2handler
Webserver = Apache/2.2.3 (Debian) mod_python/3.2.10 Python/2.4.4 PHP/4.4.4-8+etch2 mod_perl/2.0.2 Perl/v5.8.8
Datenbank = mysqlt 5.0.32-Debian_7etch1-log, lock.system=flock
Werkzeuge = ArchiveUpload, Dcraw, Exif, Ffmpeg, Getid3, LinkItemToolkit, NetPBM, Thumbnail, Gd, ImageMagick, SquareThumb
Beschleunigung = partial/900, partial/900
Betriebssystem = Linux develop 2.6.18-4-686 #1 SMP Wed May 9 23:03:12 UTC 2007 i686

 
rgr

Joined: 2007-05-22
Posts: 5
Posted: Wed, 2007-05-23 19:12

Noone an idea? Is the question to simple or to difficult? Or wrong forum?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2007-05-25 11:19
 
rgr

Joined: 2007-05-22
Posts: 5
Posted: Sun, 2007-05-27 10:46
valiant wrote:
there are already a command line clients:
http://codex.gallery2.org/Other_Clients

I saw this and wondered, why there is noone in php.

I studied it. I am not the perl guy, but it seems to me that it simply does the auth-Token into the post variable (not into get, like documented). I also tried this already, so I still understand what I am doing wrong.