First, let's prepare.
Yahoo! ID is required.
Here, Yahoo! ID as they already have, and later to write.
(If you do not have it,
Yahoo! Let's get on.
)
Yahoo! Web API to use, you first need to get under your ID.
Also, if you also do affiliate, the affiliate ID is also required.
If you want to affiliate, affiliate ID (Yahoo! Affiliate ID or, ValueCommerce of the ID or the Isure) is required.
Yahoo! If you want shopping and other affiliates, ValueCommerce of acceptable ID will get the better off.
ValueCommerce ID is
http://www.valuecommerce.ne.jp can register for free.
ValueCommerce the ID does not have a (not registered) cases, Yahoo! Affiliate ID is required.
Yahoo! Affiliate ID is, Yahoo! ID is not.
Yahoo! Affiliate ID is obtained as follows.
- http://shopping.yahoo.co.jp/affiliate/ access to.
- On the "Login" and click the Yahoo! ID to login.
After logging in, from the same screen appears, this time, the left "Yahoo! You agree to the Terms of Use Affiliate" button.
- Yahoo! Terms of Service screen appears so affiliate, if properly done, the bottom of the screen "I agree" button.
After processing is complete, return to the original screen, the left "affiliate ID Verify" button.
- Following affiliate ID will be displayed, where you'll copy the affiliate ID.
Web API ID (application ID) get to see.
- http://developer.yahoo.co.jp/ access to.
- On the "Login" and click the Yahoo! ID to login.
After logging in, from the same screen appears, this time, the right "application ID register (free)" button.
E-mail contact, OAuth Do you want to use?
Whether to accept the guidelines?
Answer the item.
OAuth is here, then leave without.
When you complete the "confirm" button.
- A confirmation screen will appear, especially if there are no mistakes "Register" button.
The following screen is the screen after completing registration.
Following "Your Yahoo! JAPAN ID applications that are registered with the ID" let's copy the part.
Enter the URL directly, try to search.
Yahoo! Web API is, URL parameters to manipulate, and access to information in XML makes reply.
So, WEB browser, you can see if the direct URL address.
Does using this page, URL to create the code, let's try.
- Yahoo! Sample of shopping to find something in the URL, Http://Developer.yahoo.co.jp/Webapi/Shopping/Shopping/V1/Itemsearch.html located.
http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch?appid=<your application id>&query=vaio
URL of this sample <your application id>: you get ahead in, Web API ID (application ID) to specify, Web browsers let you type directly.
- Information such as the following reply (XML information) think it will be displayed.
If this screen appears OK.
Check the operating environment for PHP.
Make sure that PHP can work.
The following is, Windows is an example of the command prompt confirmation.
Enter the UNIX command can be found as well.
1
2
3
4
| C:\> php -v
PHP 5.1.2 (cli) (built: Jan 11 2006 16:40:00)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
|
In this article, the version must be at least
PHP5.
Now you are ready.
Next, PHP code to the original sample, let's try.
PHP using the sample source, try this.
The following is a simple software to search for PHP is the sample source.
[sample.php]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
| //-------------------------------------------------------------------
// Define your id.
//-------------------------------------------------------------------
// user id information
define("ACCESS_KEY_ID" , 'Your Yahoo! Web API id. ');
// yid = Yahoo! affiliate id , vc = ValueCommerce id
define("AFFILIATE_COM" , 'yid/vc' );
define("AFFILIATE_TAG" , 'Your Yahoo! or ValueCommerce affiliate id.' );
// access url(Jpanan)
define("ACCESS_URL" , 'http://shopping.yahooapis.jp/ShoppingWebService/V1/');
//-------------------------------------------------------------------
//http://shopping.yahooapis.jp/ShoppingWebService/V1/itemSearch? -- item search
//http://shopping.yahooapis.jp/ShoppingWebService/V1/categorySearch? -- category search
//-------------------------------------------------------------------
// this function is encode with RFC3986 format.
//-------------------------------------------------------------------
function urlencode_RFC3986($str)
{
return str_replace('%7E', '~', rawurlencode($str));
}
//-------------------------------------------------------------------
// Main routine.
//-------------------------------------------------------------------
$base_param = 'appid='.ACCESS_KEY_ID;
$params = array();
$params['affiliate_type'] = AFFILIATE_COM;
$params['affiliate_id'] = AFFILIATE_TAG;
$params['sort'] = '-sold'; // price/name/score/sold/affiliate/review_count (+/-)
$params['type'] = 'all'; // all/any
//$params['category_id'] = 10002; // category (book)
$params['category_id'] = 2502; // category (pc/software)
$params['query'] = 'Windows 7 Microsoft'; // search key ( UTF-8 )
$params['offset'] = 0; // [1-20]
// sort $param by asc.
ksort($params);
// create canonical string.
$canonical_string = $base_param;
foreach ($params as $k => $v) {
$canonical_string .= '&'.urlencode_RFC3986($k).'='.urlencode_RFC3986($v);
}
// create URL strings.
$url = ACCESS_URL.'itemSearch?'.$canonical_string; // service = itemSearch
// request to yahoo !!
$response = file_get_contents($url);
// response to strings.
$parsed_xml = null;
if(isset($response)){
$parsed_xml = simplexml_load_string($response);
}
$err_count=0;
// print out of response.
if( $response &&
isset($parsed_xml) &&
isset($parsed_xml->attributes()->totalResultsReturned) ){
// total results num.
$total_results = $parsed_xml->attributes()->totalResultsAvailable;
// total results pages.
$total_pages = floor(($parsed_xml->attributes()->totalResultsAvailable + 19)/20);
print("All Result Count:".$total_results." | Pages :".$total_pages );
print("
<table>");
foreach($parsed_xml->Result->Hit as $current){
$nerr=0;
print("
<tr>
<td><font size='-1'>");
print('<a href="'.$current->Url.'"><img src="'.$current-- alt="" />Image->Small.'" border="0"></a>
');
print('<a href="'.$current->Url.'">'.$current->Name.'</a>
');
// print('JAN CODE : '.$current->JanCode.'
');
print($current->Price->attributes()->currency);
if($current->PriceLabel->attributes()->taxIncluded){
print( " TAX (INCLUDE) : ");
} else {
print( " TAX (Not INCLUDE) : ");
}
if(isset($current->PriceLabel->SalePrice) && $current->PriceLabel->SalePrice>0){
print('
');
if(isset($current->PriceLabel->FixedPrice) && $current->PriceLabel->FixedPrice>0){
print($current->PriceLabel->FixedPrice.'
');
} else if( (int)$current->PriceLabel->SalePrice != (int)$current->Price ){
print($current->Price.'
');
}
print('<span class="red">Sale : '.$current->PriceLabel->SalePrice.'</span>
');
} else {
print($current->Price.'
');
}
if(isset($current->Review) && isset($current->Review->Rate) && $current->Review->Count>0){
print('Rate:<a href="'.$current->Review->Url.'">');
print($current->Review->Rate.'('. $current->Review->Count .')'.'
');
print('</a><hr />');
}
print("</td>
</tr>
");
}
print("</table>
");
}
|
If used as is, if you set the following three items, "computers, peripherals" in the category, "Windows 7 Microsoft" by selling the results of search on the keyword (Ascending) Gets.
Line 6: Your Web API ID (application ID) to set up.
Line 8: your affiliate ID type (Yahoo! Affiliate ID (= yid) or ValueCommerce the ID (= vc) or be one) to set up.
Line 9: your affiliate ID (Yahoo! Affiliate ID or the ID of one or ValueCommerce) Sets.
Set in your php file I uploaded to the WEB can be accessed on the server.
WEB browser, please upload it to access php.
For example, WEB server from the current, yahoo If you upload to the directory under the following URL to access.
http://www.example.com/yahoo/sample.php
You should see the following screen appears.
Php code where the parameters, let me explain briefly.
Where necessary changes, I think the following lines.
Line 37: 'sort' specifies the order of search results.
Here, 'sold' = is specified in ascending order selling.
price:
Price
name:
Store Name
score:
Recommended by
sold:
By selling
affiliate:
Premiums by affiliate
review_count:
AZ of reviews
The top, + - and to add, - (descending) or + (Ascending) will be.
Line 38: 'type' is AND search multiple search characters (= all) or a, OR search (= any) to specify whether the.
Here, AND we conducted a search.
Line 40: 'category_id', the category ID to specify the search criteria.
Here, "2502" for "personal computer peripherals," has been specified.
Category ID is specified here, the following URL can be confirmed.
http://shopping.yahooapis.jp/ShoppingWebService/V1/categorySearch?appid=<your application id>&category_id=1
URL of this sample <your application id>: you get ahead in, Web API ID (application ID) to specify, Web browsers let you type directly.
Id is the output XML tag information, the category ID.
Line 41: 'query' is a string to search.
Here, "Windows 7 Microsoft" has conducted a search of the AND.
Line 42: 'offset' specifies whether the output from what number of search results.
One single search result, get the results up to 20 pieces.
0 means the beginning.
Search criteria, you can also specify a lot.
For more information, please see the following pages.
http://developer.yahoo.co.jp/webapi/shopping/shopping/v1/itemsearch.html Line 63: The output information is converted to the XML parser information between strings.
The explanation was simple, like this Yahoo! You can do a search and shopping.
If you have little knowledge of PHP, like Amazon's own widget for Yahoo! Can create a shopping version.
This is a human-readable, XML output I tried to create a solid.
Yahoo! Web API does, PHP is also available for it, I can create some easy to use and there.
Also, his look and touch and everything, I think better understanding.
Once it is tested invite you.
(Introduction of the book appears below, this Yahoo! Web API results are displayed with the search.
)
Leave a Reply