Home

OFF-SOFT.net

OFF-SOFT.net

This site is support & information site of WEB,and Software. This site might help you that create software or Web Site…perhaps?[:]

Use KAKAKU.com Web API with PHP

Published on| October 14th, 2009 | No Comment.
Summary:

This time, the KAKAKU.com using the Web API, I would like to see a simple search results.
KAKAKU.com Web API in an earlier article was to "PHP at Yahoo! Web API using the" The Web API is very similar to the idea.
Prices. Com is not an affiliate from, and there are no parameters around that, rest is almost the same idea.
Similarly, the output by parsing the XML information, retrieve the information you want to see yourself, HTML conversion information can be output.

This API is not easy and they can always make my own page to display the lowest.

Does, immediately, PHP let's try to create the sample code.

See page: Http://Apiblog.kakaku.com/
Sample source code you used here:


First, let's prepare.

KAKAKU.com Web API to use, you first need to get under your ID.


Web API ID (API access key) get the check.

  1. http://apiblog.kakaku.com/ access to.

  2. The left "application available" click, enter the following details of the screen form.

    When you're done, "to register and agree to the terms of the above" button.
  3. Screen appears informing you Yoshinobu email has been sent to the following provisional registration.

    Temporary registration in the mail describing s is the URL to access to complete this registration, Web API ID (API access key) can be obtained.
    Following "API access key has been issued," let's copy the part below.





Enter the URL directly, try to search.

KAKAKU.com 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.

  1. Prices. Com sample to find something in the URL, Http://Apiblog.kakaku.com/Kakakuitemsearchv1.0.Html located.
    http://api.kakaku.com/WebAPI/ItemSearch/Ver1.0/ItemSearch.aspx?Keyword=%e3%82%a2%e3%82%af%e3%82%aa%e3%82%b9&resultset=medium&categorygroup=kaden&pagenum=1&minprice=100000&maxprice=150000&ApiKey=<your application id>
    URL of this sample <your application id>: you get ahead in, Web API ID (API access key) to specify, Web browsers let you type directly.


  2. 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
//-------------------------------------------------------------------
// Define your id.
//-------------------------------------------------------------------
// user id information
define("ACCESS_KEY_ID"     , 'Your KAKAKKU.com Web API id.    ');
 
// access url(Jpanan)
define("ACCESS_URL"        , 'http://api.kakaku.com/WebAPI/ItemSearch/Ver1.0/ItemSearch.aspx');
//-------------------------------------------------------------------
//http://api.kakaku.com/WebAPI/ItemSearch/Ver1.0/ProviderSearch.aspx -- プロバイダ検索API
 
 
//-------------------------------------------------------------------
// this function is encode with RFC3986 format.
//-------------------------------------------------------------------
function urlencode_RFC3986($str)
{
    return str_replace('%7E', '~', rawurlencode($str));
}
 
 
//-------------------------------------------------------------------
// Main routine.
//-------------------------------------------------------------------
 
$base_param = 'ApiKey='.ACCESS_KEY_ID;
 
$params = array();
 
$params['SortOrder']        = 'pricerank';  //	price/name/score/sold/affiliate/review_count (+/-)
$params['CategoryGroup']    = 'Pc';         //	category (pc/software)
$params['Keyword']          = 'Windows 7 Microsoft';        // search key ( UTF-8 )
$params['HitNum']           = 10;	//	result max count.
$params['PageNum']          = 1;	//	start page no
$params['Charset']          = 'utf8';	//	charactor code
$params['ResultSet']        = 'medium';	//	result info
 
// 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.'?'.$canonical_string;	//	service = itemSearch 
 
// request to amazon !!
$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->Error)  ){
 
	// total results num.
	$total_results = $parsed_xml->NumOfResult;
	// total results pages.
	$total_pages = floor(($parsed_xml->NumOfResult + 9)/10);
 
	print("All Result Count:".$total_results."  | Pages :".$total_pages );
 
	print("<table>");
	foreach($parsed_xml->Item as $current){
		$nerr=0;
 
		print('<tr><td><font size="-1">');
 
		print('<a href="'.$current->ItemPageUrl.'"><img src="'.$current-- alt="" />ImageUrl.'" border="0"></a>');
		print('<a href="'.$current->ItemPageUrl.'">'.$current->ProductName.'</a>');
		print('Maker : '.$current->MakerName.'');
 
		print('<font color="red">Sale : '.$current->LowestPrice.'</font>');
 
		if(isset($current->PvRanking) && !empty($current->PvRanking) ){
			print('Ranking : '.$current->PvRanking.'');
		}
		if(isset($current->TotalScoreAve) && !empty($current->TotalScoreAve) ){
			print('Rate : '.$current->TotalScoreAve.'');
		}
		if(isset($current->Comment) && !empty($current->Comment) ){
			print('Spec : '.$current->Comment.'');
		}
		print("</td>
</tr>
");
	}
	print("</table>
");
	print('<a href="http://apiblog.kakaku.com/">WEB Services by 価格.com</a>');
}

If used as is, if you set the following three items, "computers, peripherals" in the category, "Windows 7 Microsoft" in order to get word from the search results. Line 6: Your Web API ID (API access key) 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, kakaku If you upload to the directory under the following URL to access.

http://www.example.com/kakaku/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.

$ params [ 'SortOrder'] = 'Pricerank'; / / price / name / score / sold / affiliate / review_count (+/-) $ params [ 'CategoryGroup'] = 'Pc'; / / category (pc / software) $ params [ 'Keyword'] = 'Windows 7 Microsoft'; / / search key (UTF-8) $ params [ 'HitNum'] = 10; / / result max count. $ Params [ 'PageNum'] = 1; / / start page no $ params [ 'Charset'] = 'Utf8'; / / charactor code $ params [ 'ResultSet'] = 'Medium'; / / result info 31 line: 'SortOrder' specifies the order of search results. Here, 'sold' = specifies the order from.
pricerank: Low → high
-pricerank: High → low
daterank: By Release Date (new → old)
popularityrank: Most Watched
* If specified Shi無I is the order of popularity.
Specify multiple ordering is not.

Line 32: 'CategoryGroup' specifies the name of the category to be searched.
Here, "Pc" of "computers, peripherals," has been specified.
The category name specified here is as follows.
Pc & Computer
Kaden Appliances
Camera Camera
Game Game
Gakki instruments
Kuruma EoCN
Sports and Leisure Sports
Brand watches Brand
Baby & Kids Baby
Pet Pet
Health and Beauty Beauty_Health
All of the above ALL

Line 41: 'Keyword' is the string to search. Here, "Windows 7 Microsoft" has conducted a search of the AND.
Line 42: 'HitNum' specifies how many pieces to maximize the output results. Here, we specify that up to 10 search results for each.
Line 43: 'PageNum' specifies whether to print many pages of search results. Here, one has to specify that the first search results page.
Line 44: 'Charset' specifies the character encoding of the search results. Here, "utf8" = UTF-8 is specified.
sjis: SHIFT-JIS
utf8: UTF-8
euc: EUC-JP
Line 43: 'ResultSet', the type of information in search results (volume) is specified. Here, "medium" = specifies the default.
mini / medium specifies either.

Search results and search criteria, you can also specify a lot. For more information, please see the following pages.
http://apiblog.kakaku.com/KakakuItemSearchV1.0.html


Line 57: The output information is converted to the XML parser information between strings.
Also
Line 98: Here is the KAKAKU.com's "credit view" is. On the terms, such as "credit view" should not and must not put the.
For more information, Http://Apiblog.kakaku.com/Credit.html Please refer to.


It was a brief description, price like this. Com you can do a search.
If you have little knowledge of PHP, for my money. Com and you can create a ranking table.

This is a human-readable, XML output I tried to create a solid. Also, his look and touch and everything, I think better understanding. Once it is tested invite you.
(Introduction of the book appears below, this KAKAKU.com Web API results are displayed with the search. )


Comments

Leave a Reply







  • はてなブックマークへ追加する
  • Facebookでシェアする
  • twitter でつぶやく
  • Google Plusでシェアする
  • Pocketでシェアする
ページトップへ