Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('ebay_appid.php');
- ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071026 Firefox/3.5');
- if (empty($appid))
- {
- echo "appid undefined.";
- exit(1);
- }
- $endpoint = "http://svcs.ebay.com/services/search/FindingService/v1?";
- $consonants = array ( "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "y" );
- $vowels = array ( "a", "e", "i", "o", "u" );
- $searchQuery = $consonants[mt_rand(0,17)] . $vowels[mt_rand(0,4)] . "*";
- $max_price = "1.00";
- $min_price = "0.89";
- $params = array (
- // the header
- 'OPERATION-NAME' => 'findItemsByKeywords',
- 'SECURITY-APPNAME' => $appid,
- 'SERVICE-VERSION' => '1.0.0',
- 'GLOBAL-ID' => 'EBAY-US',
- 'REST-PAYLOAD',
- // the query
- 'keywords' => $searchQuery,
- // max price filter
- 'itemFilter[0].name' => 'MaxPrice',
- 'itemFilter[0].value' => $max_price,
- 'itemFilter[0].paramName' => 'Currency',
- 'itemFilter[0].paramValue' => 'USD',
- // listing type
- 'itemFilter[1].name' => 'ListingType',
- 'itemFilter[1].value' => 'Auction',
- // currency
- 'itemFilter[2].name' => 'Currency',
- 'itemFilter[2].value' => 'USD',
- // exclude autopay
- 'itemFilter[3].name' => 'ExcludeAutoPay',
- 'itemFilter[3].value' => 'true',
- // feedback min
- 'itemFilter[4].name' => 'FeedbackScoreMin',
- 'itemFilter[4].value' => '100',
- // free shipping only
- 'itemFilter[5].name' => 'FreeShippingOnly',
- 'itemFilter[5].value' => 'true',
- // hide duplicates
- 'itemFilter[6].name' => 'HideDuplicateItems',
- 'itemFilter[6].value' => 'true',
- // top rated only
- 'itemFilter[7].name' => 'TopRateSellerOnly',
- 'itemFilter[7].value' => 'true',
- // location
- 'itemFilter[7].name' => 'LocatedIn',
- 'itemFilter[7].value' => 'US',
- // max bids
- 'itemFilter[8].name' => 'MaxBids',
- 'itemFilter[8].value' => '0',
- // min price filter
- 'itemFilter[9].name' => 'MinPrice',
- 'itemFilter[9].value' => $min_price,
- 'itemFilter[9].paramName' => 'Currency',
- 'itemFilter[9].paramValue' => 'USD',
- 'paginationInput.entriesPerPage' => '100'
- );
- $totalPages = 0;
- $page = 1;
- $listing = array();
- do {
- // adjust the page number
- $params['paginationInput.pageNumber'] = $page;
- // build the URL
- $url = $endpoint . http_build_query($params, '', '&');
- // get the data
- $str = @file_get_contents($url);
- if (!$str) {
- echo "Failed to get URL contents\n";
- break;
- }
- // load as xml object
- $xml = simplexml_load_string($str);
- // get the total number of pages and entries
- if (!isset($totalPagesSet)) {
- $totalPages = (int) $xml->paginationOutput->totalPages;
- $totalPagesSet = "yes";
- }
- if (!isset($totalEntries))
- $totalEntries = (int) $xml->paginationOutput->totalEntries;
- // loop through and store the URL
- foreach ($xml->searchResult->item as $item) {
- //echo (string) $item->viewItemURL . "\n";
- array_push($listing, (string) $item->viewItemURL);
- }
- // increment the page number
- $page = $page + 1;
- // safety net
- if ($page > 100) {
- echo "Safety limit reached!\n";
- break;
- }
- //sleep(5);
- } while ($page <= $totalPages);
- if (!empty($listing)) {
- echo "Today's random ebay URL item (q=$searchQuery,".count($listing)."/$totalEntries) is:\n" . $listing[mt_rand(0, count($listing) - 1)] . "\n";
- return 0;
- }
- return 1;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement