![]() | 1 | initial version |
This code works for me:
date_default_timezone_set('America/Denver');
ini_set('memory_limit','16384M');
ini_set("default_socket_timeout", 6000); // seconds
require_once("vendor/autoload.php");
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$log = new \Monolog\Logger('PHRETS');
$log->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Logger::DEBUG));
error_reporting(E_ALL & ~E_NOTICE);
$config = new \PHRETS\Configuration;
$config->setLoginUrl('http://gbhar-rets.paragonrels.com/rets/fnisrets.aspx/GBHAR/login')
->setUsername('ailchuk')
->setPassword('*')
->setRetsVersion('1.7.2');
//$config->setHttpAuthenticationMethod('digest'); // or 'basic' if required
//$config->setHttpAuthenticationMethod('basic'); // or 'basic' if required
$rets = new \PHRETS\Session($config);
$rets->setLogger($log);
try {
$connect = $rets->Login();
//var_dump($connect);
} catch (Exception $e)
{
echo "Login failed\n";
echo "Error: " . $e->getMessage() . "\n";
return;
}
//$objectIds = '10453' ;
$objectIds = '10453,45262,53286' ;
$objects = $rets->GetObject('Property', 'Photo', $objectIds, '', 1);
//var_dump($objects);
$objectCount = 0;
$objectFailedCount = 0;
foreach ($objects as $object) {
// does this represent some kind of error
echo "\n\nIsError: " . $object->isError();
if ($object->isError())
{
$objectFailedCount++;
$errorInfo = $object->getError();
//var_dump($errorInfo);
echo "\ncode: " . $errorInfo->getCode();
echo "\nmessage: " . $errorInfo->getMessage();
echo "\ngetContentId: " . $object->getContentId();
echo "\ngetObjectId: " . $object->getObjectId();
echo "\ngetContentType: " . $object->getContentType();
echo "\ngetContent: \n" . $object->getContent();
echo "\n\n";
continue;
}
$objectCount++;
// get the record ID associated with this object
echo "\ngetContentId: " . $object->getContentId();
// get the sequence number of this object relative to the others with the same ContentId
echo "\ngetObjectId: " . $object->getObjectId();
// get the description of the object
echo "\ngetContentDescription: " . $object->getContentDescription();
// get the sub-description of the object
echo "\ngetContentSubDescription: " . $object->getContentSubDescription();
// get the size of the object"s data
echo "\ngetSize: " . $object->getSize();
// does this object represent the primary object in the set
echo "\nisPreferred: " . $object->isPreferred();
// when requesting URLs, access the URL given back
echo "\ngetLocation: \n" . $object->getLocation();
// get the object"s Content-Type value
echo "\ngetContentType: " . $object->getContentType();
// get the object"s binary data
echo "\ngetContent: \n" . $object->getContent();
// use the given URL and make it look like the RETS server gave the object directly
// $object->setContent(file_get_contents('http:' . $object->getLocation()));
// echo "\nDownloaded-getSize: " . $object->getSize();
echo "\n\n";
}
echo "Object Count: $objectCount\n";
echo "Object Failed Count: $objectFailedCount\n";
echo "\n\n";
try {
$rets->Disconnect();
echo "\n";
echo "Logout" . "\n";
} catch (Exception $e)
{
echo "Logout failed\n";
echo "Error: " . $e->getMessage() . "\n";
}