Magpie questions.
Posted: 19 July 2005 04:27 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

Following the suggestion given in this thread, I have been trying to redo my review pages to use REST parsed by Magpie instead of the Amazon plugin, since {amazon_price} isn’t working for the plugin. However, I have some Magpie questions.

1) Can I use custom fields (to fetch the ASIN, locale and associate ID associated with each review) within the url fed to magpie? Currently, I have the following code, which at the moment returns nothing:

{exp:weblog:entries weblog="{current_weblog}"}

{exp
:magpie url="http://xml.amazon.com/onca/xml3?t={7_id}&dev-t=D27N4MTHRQ5C98&type=heavy&f=xml&AsinSearch={7_asin}&mode=books&page=1&locale={7_locale}" limit="1" refresh="60"}

{items}
<a href="{link}">{title}</a></li>
{/items}

{
/exp:magpie}

{
/exp:weblog:entries}

2) When Magpie has parsed the result of a REST query (see here
for an example, can I then pull in any of the data in that feed using {<variable>}, or can I only use those variables that are defined by the Magpie plugin? For example, can I use {ListPrice} and {SalesRank} right off, without writing any more code to fetch those particular fields? And if I can pull them in, can I test for them using conditionals, to see if they’re present for a particular item?

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 19 July 2005 12:24 PM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6086
Joined  08-04-2002

As you know, my REST example isn’t working totally…but, way back when I was first setting it up, I could pull/display any of the variables returned by either the “lite” or “heavy” versions. In examing the XML returned by your link, nothing is identified…<title>, <price>, etc….I think that’s the problem.
—————
If you plug in this REST url…(I’ve broken the urls and other long lines for display here in the forum)...
http://xml.amazon.com/onca/xml3?t=webservices-20&dev-t=amznRss&KeywordSearch=weblog&mode=books&bcm=&type=lite
&page=1&ct=text/xml&sort=+salesrank&f=http://xml.amazon.com/xsl/xml-rss091.xsl

You’ll get this back…
<rss version=“0.91”>
   <channel>
      <title>
          Amazon.com - Search Results for “weblog” in books
      </title>
      <link>
         http://www.amazon.com/exec/obidos/external-search
         ?mode=books&keyword=weblog&rank=%2Bsalesrank&tag=amznRss
      </link>
      <description>
         Up-to-date listings of Amazon.com’s top items (by Sales Rank).
      </description>
      <language>en-us</language>
      <docs>
         http://www.amazon.com/exec/obidos/subst/xs/syndicate.html
      </docs>
      <image>
         <title>Amazon.com—Earth’s Biggest Selection</title>
         <url>http://images.amazon.com/images/G/01/rcm/logo2.gif</url>
         <width>120</width>
         <height>30</height>
         <link>http://www.amazon.com</link>
      </image>
   <item>
      <title>
         Blog : Understanding the Information Reformation That’s Changing Your World
      </title>
      <description>
         Blog : Understanding the Information Reformation That’s Changing Your World,
         by Hugh Hewitt—$13.99
      </description>
      <link>
         http://www.amazon.com/exec/obidos/ASIN/078521187X/ref=nosimRss/webservices-20
         ?dev-t=amznRss
      </link>
   </item>
ETC…

—————
The section identifiers are there and I think that’s what Magpie needs…Just my guess.
Don’t know what the problem with yours (or my other one is) that those aren’t being returned though.
—————
Edit…In my sample page, the individual book title and link are being displayed. None of the channel stuff is though.

Profile
 
 
Posted: 19 July 2005 12:40 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

Odd that the URLs would return such different results. I got mine off one of Amazon’s help pages on REST, which one would have hoped would be updated, but that doesn’t seem to have been the case.

I’ll give tweaking yours to single-item a try as well, to see if that at least produces the same results as you have. That should allow me to determine whether I can use {<fieldname>} in the URL to pull in data.

I do wonder if it is a Magpie or an Amazon issue. I imagine you hadn’t actually done any changes just before it broke, though? That’d suggest its Amazon.

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 19 July 2005 12:41 PM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6086
Joined  08-04-2002

Uhhhhh…Never Mind...
Weird, I just plugged your link into Firefox and it now returns with the complete xml tags instead of just plain text all run together.

Profile
 
 
Posted: 19 July 2005 12:43 PM   [ Ignore ]   [ # 4 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6086
Joined  08-04-2002

I imagine you hadn’t actually done any changes just before it broke, though? That’d suggest its Amazon.

Correct…I hadn’t even looked at that page until you started the thread and it was working then. It just all of a sudden quite.

Profile
 
 
Posted: 19 July 2005 12:45 PM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

Oh, it didn’t display right at all for you to start with? I saw the tags all along, but they’re differently named than in your example. Or maybe that’s just the ‘heavy’ bit? Curious that it wouldn’t include a basic item link, like yours, though.

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 19 July 2005 12:51 PM   [ Ignore ]   [ # 6 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6086
Joined  08-04-2002

One thing I do notice is that the very first line in my returned info starts…
<rss version=“0.91”>
Whereas your’s is…(broke it in two for Forum dispaly)...
<ProductInfo xsi:noNamespaceSchemaLocation=
“http://xml.amazon.com/schemas3/dev-heavy.xsd”>

—————
Notice mine identifies it as RSS which Magpie reads.

Profile
 
 
Posted: 19 July 2005 12:54 PM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

That does seem to be part of it. I altered my URL, to add in ct=text/xml and f=http://xml.amazon.com/xsl/xml-rss091.xsl from yours. However, even with heavy specified, it then only returns the same amount as it does with lite. I wonder if one could change the rss091.xsl bit to get more info ... need to see if they cover that on Amazon’s site.

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 19 July 2005 12:59 PM   [ Ignore ]   [ # 8 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6086
Joined  08-04-2002

From what I remember, it’s strictly the heavy/lite designation that determines what’s returned. Don’t think the RSS version has anything to do with that.
——-
Edit: Have you Googled “Amazon REST” or “Amazon RSS” or “Amazon API”?
I remember there were several tutorials out there that were much easier to figure out than reading the Amazon specs.

Profile
 
 
Posted: 19 July 2005 01:02 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

Some poking around suggests that http://xml.amazon.com/xsl/xml-rss091.xsl is an XSL template, used to transform the raw XML. I wonder if this particular template ignores the extra fields available in the heavy format. If I understand things correctly, it should be possible to write an XSL template of one’s own and use that to parse the XML. If one knows anything about XML, that is. wink

Might be that Amazon as some more hidden somewhere, though.

Edited to add: Haven’t found any useful tutorials yet (not for my level, at least), but did find another thread here on the forum that discusses modifying the XSL to include more data: http://expressionengine.com/forums/viewthread/10447/

Will see what I can do with that.

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 19 July 2005 01:48 PM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

With the help of the other thread, I put up a slightly modified xsl file on my site, and it looks like it should be possible to tweak it to get the data I want from the heavy feed.

However, it does look like the URL fed to magpie can’t take variables. Can anyone confirm if this is the case, or if I am just doing something wrong? wink This is what I’ve got now:

{assign_variable:amz_start="http://xml.amazon.com/onca/xml3?"}
{assign_variable
:amz_id="{7_id}"}
{assign_variable
:amz_devtoken="{7_devtoken}"}
{assign_variable
:amz_middle="&type=heavy&ct=text/xml&f=http://www.hippoiathanatoi.com/amazon.xsl"}
{assign_variable
:amz_asin="{7_asin}"}
{assign_variable
:amz_locale="{7_locale}"}
{assign_variable
:amz_end="&mode=books&page=1"}

{exp
:weblog:entries weblog="{current_weblog}" paginate="bottom"}

{exp
:magpie url="{amz_start}{amz_id}&{amz_devtoken}{amz_middle}&{amz_asin}&{amz_locale}{amz_end}" limit="1" refresh="60" parse="inwards"}

{items}
<a href="{link}">{title}</a></li>
{/items}

{
/exp:magpie}

{
/exp:weblog:entries}

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 19 July 2005 01:55 PM   [ Ignore ]   [ # 11 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6086
Joined  08-04-2002

Looks like what you are trying to do with the variables is the same as that PHP example I had was doing…creating the Amazon url.

Profile
 
 
Posted: 19 July 2005 02:25 PM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

Right, I am just a touch daunted by PHP still. wink But it might be what’s needed. smile

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 19 July 2005 04:53 PM   [ Ignore ]   [ # 13 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6086
Joined  08-04-2002

The PHP works…pretty basic but just plugged it in in this form…without the CSS…PHP on input…
{exp:weblog:entries weblog=“amazon_products” status=“open” orderby=“title” sort=“asc”}
<?php
$url = “”;
$amazonNumber = ‘{asin_number}’;
$first = ‘http://xml.amazon.co.uk/onca/xml3?t=webservices-20&dev-t=amznRss&KeywordSearch=’;
$last = ‘&mode=books&bcm=&type=lite&page=1&ct=text/xml&sort=+salesrank&f=http://xml.amazon.co.uk/xsl/xml-rss091.xsl’;
$amazonUrl = $first.$amazonfeed.$last;
echo $amazonUrl.”<br />”
?>
{/exp:weblog:entries}

——-
It returns the ASIN number from my Amazon weblog and the url info for getting to that product (raw format, not a link).

Profile
 
 
Posted: 19 July 2005 04:53 PM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

Turns out the problem was that I had the locale stored as UK and US, and the caps caused a problem. So, its doable to put together the URL for Magpie from the contents of various custom fields, without the need for assigning variables or php (although it could no doubt clean up the rather lengthy URL).

However, after all that work, it appears that the main issue (for me, anyway) is the limitations of Magpie and the RSS format. I tried modifying the XSL file to make use of additional fields, but no go.

I then found this thread which notes that only a limited number of fields will be available to hold data from the XML field, since Magpie will only read standard RSS fields (title, link, description, about, creator, subject, summary). To make use of the info in the heavy feed, I’d need quite a few more. It is also awkward not to be able to name the fields more descriptive things instead of being stuck using {about} to get an image URL.

I guess what one would need is a dedicated plugin after all, which parses either the raw XML right off or the XSL ‘styled’ XML without being limited to standard RSS fields and fieldnames.

But at least I learned a bit about XML and XSL in the process. smile

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
Posted: 19 July 2005 05:18 PM   [ Ignore ]   [ # 15 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6086
Joined  08-04-2002

I’m not sure that that’s right….
How I got into the whole thing is a friend is a manufacturer’s rep (and one of his lines is a client). He gets all his clients on Amazon (knows all the buyers for his category)...he needed a way to check all his product lines every morning, verify stock, user recommendations/reviews, ranking within their product category, etc.
I never used XSL. It was all REST. It worked well.
—————
Now, I haven’t dealt with it since then, other than this friend and I go to coffee every morning. They have now taken everything off Amazon…well not really…they have set themselves up as Amazon merchants rather than Amazon itself. They get more money in return, and don’t have to put up with the Amazon system. Amazon’s system works really well for Books and Video cassettes, doesn’t work well for anything else unless you (as a manufacturer control it, ship direct yourself, use your own shipping vendor, control your own inventory, etc.). If you start dealing with them outside their expertise, Amazon is one F@#!*-up outfit. Three times a week I hear a 30 min. rant on Amazon. I’m surprised they are still in business. Books, Videos/DVDs, fine. Everything else, hosed to the Nth degree.
—————
Rant over.
—————
Bottom line, you shouldn’t need to deal at all with XSL.

Profile
 
 
Posted: 19 July 2005 05:23 PM   [ Ignore ]   [ # 16 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1519
Joined  05-15-2004

But if the URL fed to Magpie doesn’t include a link to an xsl file, then you get what my original link produced: raw xml.

However, I imagine that if one was writing an application to make use of that data without using Magpie to parse it, then yes, one would use the raw xml. First parsing it to xsl would, it seems, be a waste of time.

At least, that’s how I understand it. But it is well past midnight here, so mistakes are definitely possible. wink

 Signature 


:: Westeros :: Hippoi Athanatoi ::

Blackadder: “Baldrick, have you no idea what irony is?”   
Baldrick: “Yeah! It’s like goldy and bronzy, only it’s made of iron.”
Blackadder III, Amy and Amiability

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66467 Total Logged-in Users: 23
Total Topics: 84859 Total Anonymous Users: 15
Total Replies: 455329 Total Guests: 172
Total Posts: 540188    
Members ( View Memberlist )