public function __construct($url_part = null, $callback_url = null, $oauth_settings = null) { if (isset($url_part)) { self::$url_part = $url_part; } if (isset($callback_url)) { self::$callback_url = $callback_url; } if (isset($oauth_settings)) { parent::__construct($oauth_settings); } }
$tm = new trademeApiRequest($url_part, $callback_url, $oauth_settings); $res = $tm->get_access_tokens($permissions); if (!isset($res[0]['oauth_token']) || !isset($res[0]['oauth_token_secret'])) { echo $tm->build_response_error($res[0]); exit; } $tokens = $res[0]; $sql = "INSERT INTO trademe_tokens (oauth_token, oauth_token_secret) VALUES ('" . $tokens['oauth_token'] . "', '" . $tokens['oauth_token_secret'] . "')"; $GLOBALS['mysqli']->query($sql); } else { $tokens = $result->fetch_assoc(); } // Add our long life tokens to our oauth settings $oauth_settings = array_merge($oauth_settings, $tokens); // List a product // Upload product photos $product_photos = array($photos_dir . 'photo1.jpg', $photos_dir . 'photo2.jpg', $photos_dir . 'photo3.jpg'); $tm = new trademeApiRequest($url_part, $callback_url, $oauth_settings); $photo_ids = $tm->upload_photos($product_photos); // Create listing $test_product = array('product_category_id' => '0187-0442-2109-4295-', 'product_title' => "Test Product", 'product_price' => 5.0, 'product_description' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\n\r\nQuisque rhoncus quam sit amet tincidunt imperdiet.\r\n\r\nEtiam vitae bibendum velit, non venenatis est", 'photo_ids' => $photo_ids); $tm = new trademeApiRequest(); // The parameters haven't changed so we don't have to enter them again $res = $tm->list_product($test_product); if (isset($tm->last_error)) { echo $tm->build_response_error($res[0]); exit; } echo $res[0]['Description']; // Optionally store resulting listing id for future API calls //$listing_id = $res[0]['ListingId'];