Page 1 of 1

How to select a transaction of an array and check it on regu

Posted: Thu Dec 28, 2006 5:26 pm
by oskare100
Hello,
I know that this is maybe a bit complicated but I thought I could take a chance and see if someone had time to read it trough. I need help with the whole script but the main thing is How to select just one transaction of all transactions ebay is returning (see the code sample, in the end of it). I'm working on a script that will be able to "GetFeedback" to see if a user has left positive feedback and then "LeaveFeedback" positive if the feedback left was positive. Everything is built on XML, here is the functions described at ebay;

http://developer.ebay.com/DevZone/XML/d ... dback.html
http://developer.ebay.com/DevZone/XML/d ... dback.html

Unfortunately there are not many code samples at Ebay (but all codes looks the same because it is just send and receive with different variables). Below is the sample code for searching, but I've tried to edit it and it also works the same for all other Ebay API functions. So when I request "GetFeedback" the script returns the variables in that function instead and my script creates an array with the the feedback I've received and (because I don't know how to make it do anything else) creates a table in HTML with all those iteams.

I need to "select" a feedback. Then I need to get all the information about it and assignt PHP variables to them as for example $transaction_id_awaiting for the transaction id, $user_id_awaiting for the user id of that transaction and so on. Because then I need those variables to be able to use the "LeaveFeedback" function to leave feedback for that transaction/user.

Another thing is that the script can't select the same feedback/transaction from "GetFeedback" all the time because then script would loop to the next feedback is left. It should only select feedbacks/transactions that the script already hasn't left feedback for. Maybe I could store the for example 30 latest feedbacks that has been answered in a table in my database, only make Ebay return the 30 latest feedbacks left for me and then fist check the table before leaving feedbacks?

Here is the code sample;

Code: Select all

<?php
	if(isset($_POST['Query']))
	{
		//Get the query entered
		$query = $_POST['Query'];
	
	
		//SiteID must also be set in the Request's XML
		//SiteID = 0  (US) - UK = 3, Canada = 2, Australia = 15, ....
		//SiteID Indicates the eBay site to associate the call with
		$siteID = 0;
		//the call being made:
		$verb = 'GetSearchResults';
		//Regulates versioning of the XML interface for the API
		$compatabilityLevel = 433;
	
		//get an array of strings containing the required headers
		$headers = buildEbayHeaders($devID, $appID, $certID, $compatabilityLevel, $siteID, $verb);
		
		///Build the request Xml string
		$requestXmlBody = '<?xml version="1.0" encoding="utf-8">';
		$requestXmlBody .= '<GetSearchResultsRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
		$requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
		$requestXmlBody .= "<Query>$query</Query>";
		$requestXmlBody .= '</GetSearchResultsRequest>';
		
		$responseXml = sendHttpRequest($requestXmlBody, $serverUrl, $headers);
		if(stristr($responseXml, 'HTTP 404') || $responseXml == '')
			die('<P>Error sending request');
		
		//Xml string is parsed and creates a DOM Document object
		$responseDoc = domxml_open_mem($responseXml);
		
		
		//get any error nodes
		$errors = $responseDoc->get_elements_by_tagname('Errors');
		
		//if there are rrror nodes
		if(count($errors) > 0)
		{
			echo '<P><B>eBay returned the following error(s):</B>';
			//display each error
			//Get error code, ShortMesaage and LongMessage
			$code = $errors[0]->get_elements_by_tagname('ErrorCode');
			$shortMsg = $errors[0]->get_elements_by_tagname('ShortMessage');
			$longMsg = $errors[0]->get_elements_by_tagname('LongMessage');
			//Display code and shortmessage
			echo '<P>', $code[0]->get_content(), ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg[0]->get_content()));
			//if there is a long message (ie ErrorLevel=1), display it
			if(count($longMsg) > 0)
				echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg[0]->get_content()));
	
		}
		else //no errors
		{
			//get results nodes
			$itemNodes = $responseDoc->get_elements_by_tagname('Item');
			
			//see if there are any results
			if(count($itemNodes) > 0)
			{
			?>
				<TABLE cellpadding="6" cellspacing="0" border="0">
					<TR bgcolor="#BBBBBB">
						<TD><B>Id</B></TD>
						<TD><B>Title</B></TD>
						<TD><B>Price</B></TD>
						<TD><B>Started</B></TD>
						<TD><B>Ends</B></TD>
					</TR>
			<?php
				//stores the alternationg background colour of the rows
				$bgColor = "#FFFFFF";
				//go through each result
				foreach($itemNodes as $item)
				{
					//get the required nodes from the results
					$itemID = $item->get_elements_by_tagname('ItemID');
					$title = $item->get_elements_by_tagname('Title');
					$price = $item->get_elements_by_tagname('CurrentPrice');
					$startTime = $item->get_elements_by_tagname('StartTime');
					$endTime = $item->get_elements_by_tagname('EndTime');
					$link = $item->get_elements_by_tagname('ViewItemURL');
					//display the result in a table row
					?>
					<TR bgcolor="<?php echo $bgColor ?>">
						<TD><?php echo $itemID[0]->get_content(); ?></TD>
						<!-- Display the Title as a link to the item on eBay -->
						<TD><A href="<?php echo $link[0]->get_content(); ?>" target="_blank">
							<?php echo $title[2]->get_content(); ?>
							</A>
						</TD>
						<TD><?php echo $price[0]->get_content(); ?></TD>
						<TD><?php echo $startTime[0]->get_content(); ?> GMT</TD>
						<TD><?php echo $endTime[0]->get_content(); ?> GMT</TD>
					</TR>
					<?php
					//alternate the background colours
					$bgColor = $bgColor == "#FFFFFF" ? "#EEEEEE" : "#FFFFFF";
				} ?>
				</TABLE>
				<?php
			}
			else
			{
				echo '<P><B>No items found</B>';
			}
		}
	}
?>
/Oskar

Posted: Thu Dec 28, 2006 6:11 pm
by Kieran Huggins
One idea worth exploring is to store the sha1 or md5 hash of an xml comment chunk, checking if it's already been processed.

Can you limit your ebay query by date? a ate would be an easy thing to store locally.

Is php5 and the DOM object available to you?

Posted: Fri Dec 29, 2006 3:52 am
by oskare100
Hello,
I can limit the feedback I receive from Ebay by number but not by date.
I've just PHP4 but I've installed the DOM package.
I don't know where to start, so what do you think would be a good solution?

/Oskar R

Posted: Fri Dec 29, 2006 4:02 am
by volka
oskare100 wrote:I've just PHP4 but I've installed the DOM package.
worth mentioning: not dom but domxml

Posted: Fri Dec 29, 2006 4:40 am
by oskare100
Hello,
Well, yes, I ment domxml too. It took me a long time to figure out how to install it but now it works, I've tried with the code sample and I can get results with the domxml function. Do you know how it it is possible to just select one or two of the items the script is returning and add variables as for example $item_id and so on to the selected item?


Thanks,
/Oskar

Posted: Fri Dec 29, 2006 4:47 am
by volka
Did you take a look at https://ebatns.codebase.ebay.com/ ?

Posted: Fri Dec 29, 2006 7:15 am
by oskare100
Hello,
Thanks, I havn't seen that one and I'll definately download it and try it but the main thing about that script seams to be that it doesn't use DOMXML and I already have installed that now (after a lot of problems) and it is working. What I need (and am trying to create) is a script that automatically can leave feedback when feedback is left for me for a transaction and that script doesn't seam to be able to do that, it can just list the feedback as in the search code example in my first post.. Do you have any idea of how that could be done?

/Oskar

Posted: Fri Dec 29, 2006 10:01 am
by volka
I just tried to setup a test account. But since really nothing went smooth from step one I'll continue to keep ebay in a Somebody Else's Problem field.
Sorry, can't help you.

Posted: Fri Dec 29, 2006 7:02 pm
by volka
I take that back. There was something wrong with "step 1" but the developer/customer support responded prompt and well. A new set of keys is assigned to the account and it all looks well ...except it's 2:00am and I'm going to bed now ;)