You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've added some simple examples in `examples.php`. To run them create a file called `secretKeys.php` containing your secret keys:
18
+
19
+
```php
20
+
<?php
21
+
$keyId = 'YOUR-AWS-KEY';
22
+
$secretKey = 'YOUR-AWS-SECRET-KEY';
23
+
$associateId = 'YOUR-AMAZON-ASSOCIATE-ID';
24
+
?>
25
+
```
26
+
27
+
and then run the examples with:
28
+
29
+
```shell
30
+
php examples.php
31
+
```
13
32
14
33
## Usage
15
-
Include the library in your code
34
+
Include the library in your code:
16
35
17
-
require_once( 'AmazonAPI' )
36
+
```php
37
+
include_once('./AmazonAPI.php');
38
+
```
18
39
19
-
Instantiate the class using your secret keys
40
+
Instantiate the class using your secret keys:
20
41
21
-
$keyId = 'YOUR-AWS-KEY';
22
-
$secretKey = 'YOUR-AWS-SECRET-KEY';
23
-
$associateId = 'YOUR-AMAZON-ASSOCIATE-ID';
42
+
```php
43
+
// Keep these safe
44
+
$keyId = 'YOUR-AWS-KEY';
45
+
$secretKey = 'YOUR-AWS-SECRET-KEY';
46
+
$associateId = 'YOUR-AMAZON-ASSOCIATE-ID';
24
47
25
-
$amazonAPI = new AmazonAPI( $keyId, $secretKey, $associateId );
48
+
$amazonAPI = new AmazonAPI($keyId, $secretKey, $associateId);
49
+
```
50
+
51
+
**Note:** Keep your Amazon keys safe. Either use environment variables or include from a file that you don't check into GitHub.
26
52
27
53
It supports all Amazon regions:
54
+
28
55
* Canada ('ca')
29
56
* China ('cn')
30
57
* Germany ('de')
@@ -35,101 +62,141 @@ It supports all Amazon regions:
35
62
* United Kingdom ('uk')
36
63
* United States ('us').
37
64
38
-
The default is UK but to set the locale call SetLocale __before__ calling the product methods. E.g.
65
+
The default is UK but to set the locale call `SetLocale()`__before__ calling the product methods. E.g.
39
66
40
-
$amazonAPI->SetLocale( 'us' );
67
+
```php
68
+
$amazonAPI->SetLocale('us');
69
+
```
41
70
42
-
By default it will use HTTP but if you need to use SSL then call the following before using the product methods and it will connect to the HTTPS endpoints:
71
+
By default it will use HTTPS, but if you don't want to use SSL then call the following before using the product methods and it will connect to the HTTP endpoints:
43
72
44
-
$amazonAPI->SetSSL( true );
73
+
```
74
+
$amazonAPI->SetSSL(false);
75
+
```
76
+
77
+
**Note:** I have no idea why I originally had this method. Perhaps the Amazon Product API didn't use SSL at one point. I've enabled HTTPS as default now but you can turn it off if you need to. I assume you won't.
45
78
46
79
### Item Search
47
80
To search for an item use the ItemSearch method:
48
81
49
-
// Search for Harry Potter items in all categories
To determine valid categories for search call GetValidSearchNames() :
92
+
By default, the `ItemSearch` method will search by featured. If you want to sort by another category then pass a 3rd parameter with the name of the category you wish to sort by. These differ by category type but the two you'll probably need are `price` (sort by price low to high) or `-price` (sort by price high to low). See [ItemSearch Sort Values](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/APPNDX_SortValuesArticle.html) for more details.
56
93
57
-
// Get an array of valid search categories we can use
By default the data will be returned as SimpleXML nodes. However if you call SetRetrieveAsArray() then a simplified array of items will be returned. For example:
122
+
By default the data will be returned as SimpleXML nodes. However if you call `SetRetrieveAsArray()` then a simplified array of items will be returned. For example:
72
123
73
-
// Return XML data
74
-
$amazonAPI = new AmazonAPI( $keyId, $secretKey, $associateId );
string(40) "Harry Potter and the Philosopher\'s Stone"
187
+
…
188
+
```
130
189
131
190
## TODO
191
+
132
192
* Need to make the simplified data less hardcoded!
193
+
* Make this a Composer package
194
+
* Add unit tests
133
195
134
196
## Thanks
197
+
135
198
This library uses code based on [AWS API authentication For PHP](http://randomdrake.com/2009/07/27/amazon-aws-api-rest-authentication-for-php-5/) by [David Drake](https://github.com/randomdrake).
0 commit comments