Created
February 20, 2012 04:06
-
-
Save s3u/1867773 to your computer and use it in GitHub Desktop.
Example (PHP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function curl_get($url) | |
| { | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
| $output = curl_exec($ch); | |
| curl_close($ch); | |
| return $output; | |
| } | |
| function get_many($urls) { | |
| $mh = curl_multi_init(); | |
| $chs = array(); | |
| for($i = 0; $i < sizeof($urls); $i++) { | |
| $ch = curl_init($urls[$i]); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_multi_add_handle($mh, $ch); | |
| array_push($chs, $ch); | |
| } | |
| $running = null; | |
| do { | |
| curl_multi_exec($mh, $running); | |
| } | |
| while ($running); | |
| $responses = array(); | |
| for($i = 0; $i < sizeof($chs); $i++) { | |
| $resp = curl_multi_getcontent($chs[$i]); | |
| array_push($responses, json_decode($resp)); | |
| } | |
| return $responses; | |
| } | |
| function post_many($urls, $headers, $bodies, $is_xml) { | |
| $mh = curl_multi_init(); | |
| $chs = array(); | |
| for($i = 0; $i < sizeof($urls); $i++) { | |
| $ch = curl_init($urls[$i]); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
| curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
| curl_setopt($ch, CURLOPT_UPLOAD, true); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, $headers[$i]); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, '$bodies[$i]'); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_multi_add_handle($mh, $ch); | |
| array_push($chs, $ch); | |
| } | |
| $running = null; | |
| do { | |
| curl_multi_exec($mh, $running); | |
| } | |
| while ($running); | |
| $responses = array(); | |
| for($i = 0; $i < sizeof($chs); $i++) { | |
| $resp = curl_multi_getcontent($chs[$i]); | |
| if($is_xml) { | |
| $resp = simplexml_load_string($resp); | |
| } | |
| else { | |
| $resp = json_decode($resp); | |
| } | |
| array_push($responses, $resp); | |
| } | |
| return $responses; | |
| } | |
| $keyword = 'ferrari'; | |
| $apikey = 'aaa'; | |
| $authtoken = 'bbb'; | |
| $url = 'http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.8.0&GLOBAL-ID=EBAY-US&SECURITY-APPNAME=' | |
| . $apikey . '&RESPONSE-DATA-FORMAT=XML&keywords=' | |
| . $keyword . '&paginationInput.entriesPerPage=5&paginationInput.pageNumber=1&outputSelector(0)=SellerInfo'; | |
| $str = curl_get($url); | |
| // Convert to JSON | |
| $items = simplexml_load_string($str); | |
| $ids = array(); | |
| for ($i = 0; $i < sizeof($items->searchResult->item); $i++) { | |
| $item = $items->searchResult->item[$i]; | |
| array_push($ids, $items->searchResult->item[$i]->itemId); | |
| } | |
| $response = array(); | |
| // User | |
| $url = 'http://open.api.ebay.com/shopping?callname=GetUserProfile&responseencoding=JSON&appid=' | |
| . $apikey . '&version=721&IncludeSelector=Details&UserID=sallamar'; | |
| $user = json_decode(curl_get($url)); | |
| $response['user'] = $user; | |
| // getSingleItem | |
| $urls = array(); | |
| for($i = 0; $i < sizeof($ids); $i++) { | |
| $url = 'http://open.api.ebay.com/shopping?callname=GetSingleItem&responseencoding=JSON&appid=' | |
| . $apikey . '&version=715&IncludeSelector=&ItemID=' . $ids[$i]; | |
| array_push($urls, $url); | |
| } | |
| $response['items'] = get_many($urls); | |
| // getBestOffers | |
| $urls = array(); | |
| $headers = array(); | |
| $bodies = array(); | |
| for($i = 0; $i < sizeof($ids); $i++) { | |
| $url = 'https://api.ebay.com/ws/api.dll?appid=' . $apikey .'&version=723'; | |
| array_push($urls, $url); | |
| $body = '<?xml version="1.0" encoding="utf-8"?><GetBestOffersRequest xmlns="urn:ebay:apis:eBLBaseComponents">' | |
| . '<ItemID>' . $ids[$i] .'</ItemID>' | |
| . '<RequesterCredentials>' | |
| . '<eBayAuthToken>' . $authtoken . '</eBayAuthToken>' | |
| . '</RequesterCredentials>' | |
| . '</GetBestOffersRequest>'; | |
| array_push($bodies, $body); | |
| $header = array(); | |
| array_push($header, 'content-type: application/xml; charset=UTF-8'); | |
| array_push($header, 'x-ebay-api-siteid: 0'); | |
| array_push($header, 'x-ebay-api-compatibility-level: 723'); | |
| array_push($header, 'x-ebay-api-call-name: getBestOffers'); | |
| array_push($header, 'x-ebay-api-app-name: eBayinc2e-d3b4-4a21-a765-47cc6b01cf7'); | |
| array_push($header, 'x-ebay-api-dev-name: 101e429b-df77-47ee-80f5-349eabe13c42'); | |
| array_push($header, 'x-ebay-api-cert-name: 6c620af8-6fec-418c-bc40-35d7dd89fd8b'); | |
| array_push($header, 'Transfer-Encoding: chunked'); | |
| array_push($header, 'Connection: close'); | |
| array_push($headers, $header); | |
| } | |
| $response['bestOffers'] = post_many($urls, $headers, $bodies, True); | |
| // getAllBidders | |
| $urls = array(); | |
| $headers = array(); | |
| $bodies = array(); | |
| for($i = 0; $i < sizeof($ids); $i++) { | |
| $url = 'https://api.ebay.com/ws/api.dll?appid=' . $apikey .'&version=723'; | |
| array_push($urls, $url); | |
| $body = '<?xml version="1.0" encoding="utf-8"?>' | |
| .'<GetAllBiddersRequest xmlns="urn:ebay:apis:eBLBaseComponents">' | |
| .'<ErrorLanguage></ErrorLanguage>' | |
| .'<OutputSelector></OutputSelector>' | |
| .'<WarningLevel>High</WarningLevel>' | |
| .'<CallMode>ViewAll</CallMode>' | |
| .'<IncludeBiddingSummary>true</IncludeBiddingSummary>' | |
| .'<ItemID>' . $ids[$i] .'</ItemID>' | |
| .'<RequesterCredentials>' | |
| .'<eBayAuthToken>' . $authtoken . '</eBayAuthToken>' | |
| .'</RequesterCredentials>' | |
| .'</GetAllBiddersRequest>'; | |
| array_push($bodies, $body); | |
| $header = array(); | |
| array_push($header, 'content-type: application/xml; charset=UTF-8'); | |
| array_push($header, 'x-ebay-api-siteid: 0'); | |
| array_push($header, 'x-ebay-api-compatibility-level: 723'); | |
| array_push($header, 'x-ebay-api-call-name: getAllBidders'); | |
| array_push($header, 'x-ebay-api-app-name: xxx'); | |
| array_push($header, 'x-ebay-api-dev-name: yyy'); | |
| array_push($header, 'x-ebay-api-cert-name: zzz'); | |
| array_push($header, 'Transfer-Encoding: chunked'); | |
| array_push($header, 'Connection: close'); | |
| array_push($headers, $header); | |
| } | |
| $response['allBidders'] = post_many($urls, $headers, $bodies, True); | |
| echo json_encode($response); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment