By eviljoker7075 on
Hey guys, I need to somehow integrate my code for Amazon Web Services into my node template. Basically I need to know how I can automatically pick up the node title (which is an album name) and artist name and place them in my AWS script to automatically display an album cover.
I have contemplate module installed. The code that gathers and displays the artist name is as follows:
<div class="field field-type-text field-field-artist-name">
<h3 class="field-label">Artist Name</h3>
<div class="field-items">
<?php foreach ((array)$field_artist_name as $item) { ?>
<div class="field-item"><?php print $item['view'] ?></div>
<?php } ?>
</div>
</div>
The album name (node title) is:
<?php print $title ?>
The code I need to somehow import these items into is as follows. The place I need to input the data is in line 3 and 4:
<?
$accesskey = ('############');
$artist = urlencode('enter_artist_name_here');
$album = urlencode('enter_album_name_here');
$images = file_get_contents('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId='.$accesskey.'&Operation=ItemSearch&SearchIndex=Music&ResponseGroup=Images&Artist='.$artist.'&Title='.$album.'');
include('xml.php');
$data = XML_unserialize($images);
$error = $data[ItemSearchResponse][Items][Request][Errors][Error][Message];
$smallimage = $data[ItemSearchResponse][Items][Item][0][SmallImage][URL];
$mediumimage = $data[ItemSearchResponse][Items][Item][0][MediumImage][URL];
$largeimage = $data[ItemSearchResponse][Items][Item][0][LargeImage][URL];
if (!$error) {
print ('
<img src="'.$smallimage.'" />
<img src="'.$mediumimage.'" />
<img src="'.$largeimage.'" />
');
} else {die($error);}
?>
Thank you for your help!
Comments
have you tried inserting the variables?
Given that you have the aforementioned flow in your file, have you tried just inserting the variables within the urlencode brackets? Like:
completely untested, and I might be completely wrong, but to start with the obvious :)
HTH
/elfur.is
Yeah I tried that, it
Yeah I tried that, it completely mucked everything up.. It simply displays the main elements of the niode in an unformatted way (including no templates etc...)
Sounds like the problem is
Sounds like the problem is either that one (or both) of the variables contain something more than the raw data you are after or that there's a different error in the code.
For debugging reasons, have you tried entering ('hard coding') the artist name and album title in lines 3 and 4 in the AWS codepart?
If that works fine, the error is in the variables, if that doesn't work, the code is incomplete.
HTH
/elfur.is
Yep hard coding works
Yep hard coding works fine... which is both good and bad I guess... How can I overcome this problem?
Then you 'just' need to
Then you 'just' need to extract the information from the variables in the proper way :)
I'm sorry I'm not experienced enough to know how to do that.
If this was still version 4.5. something, I could tell you :)
But you're working with CCK aren't you?
And I know little about that
sorry
/elfur.is
Also..
I checked the database entry and the only things it has stored under the artist and album fields are the artist and album names... nothing extra. Also, when I place several copies of the code to get the album name all I recieve in the page is the album name over and over again - so it can't be retrieving anything else, can it?
Huh, the album name and not
Huh, the album name and not a single space or anything inbetween the code?
Could it be that the urlencode() isn't liking the variable in there (that can't be)
can you paste the exact code of lines 3 and 4 in the AWS part, *after* you've inserted the variables in there?
Oh and you only mention the album name there ... have you done the same test for the artist?
/elfur.is
Ok, here's the code with the
Ok, here's the code with the hard coded variables, like this it works fine:
How do you mean I only mention the album name here.. which bit do you mean exactly?
Ah, it's clearly getting
Ah, it's clearly getting late. I meant with the $variables :) which should look something like:
Hoping that since the variables are turning up 'clean' that there might have been something 'unclean' in the way you tested it :)
As with album name and title. In the reply earlier you mention that you tried pasting the album name over and over again, and that it worked. Did you try that with the artist name? Meaning that because you're working with two different variables here, either one might be the faulty one.
Maybe you should try extracting the artist name and assigning that into a 'simple' variable before you urlencode() it. Something like:
but I'm skating on thin ice here.
I'm signing off after this reply, so good luck and hopefully you'll figure out the problem here.
HTH
/elfur.is
discography,,
Hi evil..
Just wondering if you tried the discography.module as an alternative.
Dub
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
I didn't even know that
I didn't even know that discography module existed. Does it allow the same automation of album cover retrievals etc as I am aiming for. IE, the user doesn't need to find the information, it will be autoimatically found simply through their inputed artist and album name?
I dont think so..
HI Evil..
I don't think the discography.module does that out of the box...
It's an interesting idea by the way (joining a few fields together to pull automatically pull down an album cover)
It's late here..but, I'm doing a bit of drupal work tomorrow (sunday) if you're still stuck...
Does it have to be amazon? or can it be www.last.fm the album cover is pulled from?
Dub
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
Fraid it has to be Amazon,
Fraid it has to be Amazon, due to legal issues etc, they have a whole system set up to allow people to do this you see. Also I have plans to integrate it with the affiliate scheme, but one step at a time eh?!
Had a thought... Is there any way (forgive me if this is silly as I am new to drupal and PHP) you could call up the values of artist name and album title to another section of the file (not published, but so the content of those fields are xposed and could then be picked up in a hard coded form? Maybe into an external .txt file or something?...
not sure..
I'm not sure Evil.
you could try the amazon_wrapper.inc that has a set of functions that treats the amazon item like a cache.
Or the Amazon items module that Allows sites to display products within nodes via the web services of Amazon.com
It's late at this end...give me shout tomorrow if you get stuck. the amazon items module sounds like it might be helpful, but it needs to b upgraded to 4.7 (I think)
Dub
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
another idea
I have tried an amazon module - but it only worked for books as I seem to remember, and was generally not really related to what I wanted.
There must be a way to achieve what I'm after. I know I don't know much about PHP but it's gotta be fairly simple - I mean this is what PHP is for lol.
Another thought... would it be possible to create a new query seperate to the one alreay created? I know the code would look nothing like this but the general idea behind my idea could be manifested as follows: this being just the two lines in the AWS code to get artist and album names
NOTE: the album name is used as the default node title field.
try this
this is just a wild guess..
Dub
Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate
You are nearly a genius!!
You are nearly a genius!! That is almost it, howe3ver no value is being passed for the node title. If I insert that code it displays the first item from Amazon's database for the artist, but not the correct album. So for example I had a test review for 'Meddle' by Pink Floyd - but when I opened the page it displayed the cover of Dark Side of the Moon.
But this is nearly it!! Should there be some sort of [view] bit after the nodetitle?
try using the $title variable
As you said earlier that the $title variable was good, publishing exactly what you needed, try putting that one in the later line:
/elfur.is
That's it!! Perfect. It
That's it!!
Perfect. It works brilliantly... with one exception... If the album cannot be found then the screen loses all formatting again... Is there anyway I can display a default 'not found' image which is stored on my server if the album cannot be found on amazon?
Yay :)
Yay :)
Re. when the album is not found on Amazon, what you need to do is make sure that there is a replacement image to be used, when AWS doesn't find one.
Looking at your previously pasted AWS code, it is supposed to catch errors and behave, but you might want to try changing the error portion of that code a little bit. Where you have now:
try changing this to:
where you change the url to the image, of course :)
HTH
/elfur.is
hmm, that doesn't seem to
hmm, that doesn't seem to work... I tried using a relative and absolute path to the image but both don't work. In fact it stops the script working all together and the entire node text is missing when I use the script. That is to say on both the reviews for the albums that are on amazon and those that aren't nothing is displayed in the content box.
Just for easy refference here is the AWS I am now using:
oops
oops,
there's a semicolon missing in my suggested line, try adding a semicolon at the end of the 'noalbum' line. Like this:
/elfur.is
That's it!! Will you marry
That's it!! Will you marry me!! lol
It's taken nearly a week to get right but it's finally functioning properly!!
I am so grateful to you all for helping :) I really appreciate it!! Thank you so much!!!
=D
:)
Good to see that it worked.
You know ... I might use parts of that code myself on a project I'm working on :)
Good luck
/elfur.is
Well, my site is nearing
Well, my site is nearing completion now, thank to your efforts :-D Feel welcome to take a look - it's still in the construction stages at the moment though: www.allcdreviews.com
What sorta site you working on?
yet another social networking community
I'm working on a localised social network community - an Icelandic one, for the Icelandic ones - based around the concept of alumni.
/elfur.is
Ahh, sounds cool - good luck
Ahh, sounds cool - good luck with your project :-D