Has anyone succesfully tied their system into Amazon's XML feed with
ColdFusion 4.5?  I managed to get it to work with some code I found in their
developer's forums, but it's awfully slow.  (Takes about 10 seconds to load)

Here's the code:

<CFPARAM name="page" default="1">
<CFPARAM name="mode" default="books">
<CFPARAM name="productinfo" default="#StructNew()#">
<CFPARAM name="associatesID" default="markwarrickA">
<cfparam name="developerID" default="enteryouridhere">
<cfparam name="SearchType" default="KeywordSearch">
<cfparam name="resultstype" default="lite">
<cfparam name="taglist"
default="asin,imageurlsmall,imageurlmedium,imageurllarge,releasedate,manufac
turer,listprice,ourprice,usedprice,collectibleprice,salesrank,decsription,me
dia,numemdia,Avgcustomerrating">

<CFSET
aURL="http://xml.amazon.com/onca/xml?v=1.0&t=#associatesID#&dev-t=#developer
ID#&#SearchType#=#URLEncodedFormat(term)#&mode=#mode#&type=#resultstype#&pag
e=#page#&f=xml">

<CFHTTP method="get" url="" resolveurl="yes" >
</CFHTTP>

<CFSET listcount = 0>
<cfset nexttoken = 2>
<CFSET string = "">
<CFSET author = "">
<CFSET browsename = "">
<CFSET similarproducts = "">
<CFSET token = GetToken(cfhttp.FileContent,1,"<>")>
<CFSET AmazonArray = ArrayNew(1)>
<CFLOOP condition="token NEQ '/ProductInfo'">
<CFSET nexttoken = nexttoken + 1>
<CFIF Left(token,7) EQ "Details">
<CFSET listcount = listcount + 1>
<CFSET productinfo = StructNew()>

<!---- this bit is just to grab the URL to pass through as LinkURL, as it's
hard to deal with attributes in tags--->
<CFIF ListLen(token,'"') GTE 2>
<CFSET linkURL = ListGetAt(token,2,'"')>
<CFSET tmp =
StructInsert(productinfo,"LinkURL",ListGetAt(token,2,'"'),true)>
</CFIF>

<CFELSEIF token EQ "ProductName">
<CFSET tmp =
StructInsert(productinfo,token,getToken(cfhttp.filecontent,nexttoken,"<>"),t
rue)>

<!--- For author,browsename, similarproducts I merge all these into one
string to pass through - otherwise the structure barfs --->
<CFELSEIF token EQ "Author">
<CFIF author NEQ "">
    <CFSET author = author & ", " &
getToken(cfhttp.filecontent,nexttoken,"<>")>
   <CFELSE>
<CFSET author = author & getToken(cfhttp.filecontent,nexttoken,"<>")>
   </CFIF>
   <CFSET tmp = StructInsert(productinfo,"author",author,true)>

<CFELSEIF token EQ "Artist">
<CFIF author NEQ "">
    <CFSET author = author & ", " &
getToken(cfhttp.filecontent,nexttoken,"<>")>
<CFELSE>
<CFSET author = author & getToken(cfhttp.filecontent,nexttoken,"<>")>
</CFIF>
<CFSET tmp = StructInsert(productinfo,"author",author,true)>

<CFELSEIF token EQ "BrowseName">
<CFIF browsename NEQ "">
    <CFSET browsename = browsename & ", " &
getToken(cfhttp.filecontent,nexttoken,"<>")>
<CFELSE>
    <CFSET browsename = browsename &
getToken(cfhttp.filecontent,nexttoken,"<>")>
</CFIF>
<CFSET tmp = StructInsert(productinfo,"browsename",browsename,true)>

<CFELSEIF token EQ "similarproducts">
<CFIF similarproducts NEQ "">
    <CFSET similarproducts = similarproducts & ", " &
getToken(cfhttp.filecontent,nexttoken,"<>")>
<CFELSE>
<CFSET similarproducts = similarproducts &
getToken(cfhttp.filecontent,nexttoken,"<>")>
</CFIF>
<CFSET tmp =
StructInsert(productinfo,"similarproducts",similarproducts,true)>

<!--- everything else is handled here ---->
<CFELSEIF ListFindNoCase(taglist,token)>
<CFSET tmp =
StructInsert(productinfo,token,getToken(cfhttp.filecontent,nexttoken,"<>"),t
rue)>

<!--- clean up done here for the next iteration --->
<CFELSEIF token EQ "/Details">
<CFSET browsename = "">
<CFSET author = "">
<CFSET similarproducts = "">
<CFSET AmazonArray[listcount] = productinfo>
</CFIF>
  <CFSET token = getToken(cfhttp.filecontent,nexttoken,"<>")>

</CFLOOP>

<!---
Is it an Array? #IsArray(AmazonArray)#<br>
What is the length of it? #ArrayLen(AmazonArray)#
#StructFind(productinfo,ii)#

#cfhttp.filecontent#

ASIN IMAGEURLLARGE IMAGEURLMEDIUM IMAGEURLSMALL LINKURL MANUFACTURER
OURPRICE PRODUCTNAME
--->

<!--- <cfoutput>
#StructFind(productinfo,"ASIN")#

Number of Products: #ArrayLen(AmazonArray)#<br>

</cfoutput> --->

<cfif ArrayLen(AmazonArray) gt 0>
<cfoutput>
<hr>
<font size="#application.tablefontsize#" face="#application.tablefontface#">
<br>

<b>Based on your search criteria, we believe you may be interested in the
following publication<cfif ArrayLen(AmazonArray) gt 1>s</cfif>:</b>
<br>
<br>

<cfloop from="1" to="#ArrayLen(AmazonArray)#" index="zz">
#zz#.  <a href=""> target="_Amazon">#AmazonArray[zz].PRODUCTNAME#</a> by
#AmazonArray[zz].MANUFACTURER#<br>
<br>
</cfloop>

</cfoutput>

<!--- now reset the array --->
<cfset AmazonArray = "">

</cfif>

=======================================================
Mark Warrick, CTO ZapConnect.com
Email: [EMAIL PROTECTED]
Phone: (714) 771-5782
=======================================================

[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to