문제

I'm having a few issues using the amazon API to search for ISBN.

The code seams to work for a FEW isbn's and returns some results however the majority of books (mainly factual/reference books) I search for via ISBN return no results.

To test I am getting the ISBN-10 number from amazon. I have also then tested by searching for this isbn through their own search.

This is the code we use to get the results.. I dont suppose anyone can spot a flaw?

function getBooks($isbn){
    $client = new AmazonECS('AWS_API_KEY', 'AWS_API_SEECRET_KEY', 'co.uk', 'tutorp-21');
    $response  = $client->responseGroup('Small,Images,EditorialReview')->category('Books')->search($isbn);

$books = array();

if($response->Items->TotalResults > 1){
    foreach($response->Items->Item as $item)
        $books[] = parseItem($item);
}else if($response->Items->TotalResults == 1){
    $books[] = parseItem($response->Items->Item);
}

return $books;
}

Cheers

Edit : Just to clarify... The problem we are facing is that only some ISBN numbers return results. Even though these books exist in Amazon they dont seam to return any results when searched through the API

도움이 되었습니까?

해결책 2

The problems was books that didn't have editorials. The code written works fine but needed exceptions for books being returned without all the information.

다른 팁

Without looking into the AmazonECS API, I'd expect TotalResults of 1 to return an array containing a single item still; the assignment in your else clause via parseItem($response->Items->Item) will fail accordingly (i.e. books[] remains empty), because $response->Items->Item is still an array and cannot be parsed into an item.

Consequently you should drop the else clause and adjust your condition to test for 0 instead (or >= 1 of course), e.g.:

// [...]
if($response->Items->TotalResults > 0){
    foreach($response->Items->Item as $item)
        $books[] = parseItem($item);
}
// [...]

Update

The Show first 10 results example of the Amazon ECS PHP Library confirms my expectations, the result loop is implemented like so:

//check that there are items in the response
if (isset($response['Items']['Item']) ) {

    //loop through each item
    foreach ($response['Items']['Item'] as $result) {
        // [...]
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top