First time here? Check out the FAQ!
0

Cannot Get GetObject to pull anything

  • retag add tags

I've scoured the other posts for help but what others say works will not for me. Please let me know what I am doing wrong.

<?php
date_default_timezone_set('America/Denver');
ini_set('memory_limit','16384M');
ini_set("default_socket_timeout", 6000); // seconds

require_once("vendor/autoload.php");

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'); // HTTP use 'digest'
//$config->setHttpAuthenticationMethod('basic'); // HTTPS use 'basic'

//var_dump($config);

$rets = new \PHRETS\Session($config);
//var_dump($rets);

try {
$connect = $rets->Login();
//var_dump($connect);
} catch (Exception $e)
{
echo "Login failed\n";
echo "Error: " . $e->getMessage() . "\n";
return;
}

// $system = $rets->GetSystemMetadata();
// var_dump($system);
$query = "(L_ListingId=0+)";

try {

echo "\n";
$results = $rets->Search('Property', 'RE_1', $query, ['Limit' => 1, 'Count' => 2]);
$recordCount = $results->getTotalResultsCount();
echo "Record Count: {$recordCount}\n\n";

echo "Search Results:" . "\n";

$objectIds = $listingID;
$objects = $rets->GetObject('Property', 'Photo', '10453', '*', 1);

$objectCount = 0;
$objectFailedCount = 0;

foreach ($objects as $object) {
// Does this represent some kind of error
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";

} catch (Exception $e)
{
echo "Search failed \n";
echo "Error: " . $e->getMessage() ."\n";
    echo $query;
}

try {
$rets->Disconnect();
echo "\n";
echo "Logout" . "\n";
} catch (Exception $e)
{
echo "Logout failed\n";
echo "Error: " . $e->getMessage() . "\n";
}
?>
ailchuk's avatar
ailchuk
asked 2020-01-30 10:53:19 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

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";
}

bwolven's avatar
bwolven
answered 2020-01-31 09:52:41 -0500
edit flag offensive 0 remove flag delete link

Comments

Were you able to get this working?

bwolven's avatar bwolven (2020-01-31 15:35:26 -0500) edit

Unfortunately no. It shows Record Count: 13259 Search Results: I know that the ID that I'm pulling has one photo but none of the echo statements show up after the Search Results. This is my page so you can see what I mean. http://www.grapevineweb.com/ts/search...

ailchuk's avatar ailchuk (2020-01-31 15:58:48 -0500) edit

Did you try the script that I pasted in the Answer?
By the way, image URLs that start with //cdn you need to put either "HTTP:" or "HTTPS:" depending on your particular needs.

bwolven's avatar bwolven (2020-01-31 16:00:42 -0500) edit

Sorry. It was reloading a cached page. Just tried it again and now I'm getting Object Count: 0 Object Failed Count: 0 Logout

ailchuk's avatar ailchuk (2020-01-31 16:08:45 -0500) edit

I just run my script in console mode because I'm not a PHP developer.

bwolven's avatar bwolven (2020-01-31 16:13:31 -0500) edit

Were you able to get this working?

bwolven's avatar bwolven (2020-02-04 10:48:36 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer