Taobao API interface sealed with Python (item_get to get Taobao product details, item_search to search Taobao products by keyword, item_review to get Taobao product reviews item_fee to get Taobao product fast

API (Application Programming Interface) is the abbreviation of application programming interface, which is a set of specifications that define the interaction between various components in a software system. In simple terms, API provides a common way for different software systems to exchange data and information with each other.

APIs are often used to allow different software applications to cooperate with each other. For example, a website might use a third-party API to obtain weather forecast data, or an application might use the Google Maps API to display maps.

According to different implementation methods, API can be divided into Web API, local API and government open API. Web API is an API based on the HTTP protocol, usually used for communication between web applications; local API is used for communication between desktop applications or mobile applications; government open API is an interface that government departments open to the society. Provides access to government public data.

Taobao API Access Instructions

Parameter Description

  • General parameter description
    • Do not pass parameters indiscriminately, otherwise fees will be deducted regardless of success or failure
    • url description https://api-gw.onebound.cn/platform/API type/ Platform: Taobao, Jingdong, etc., API type: [item_search, item_get, item_search_shop, etc.]
    • version: API version
    • key: call key, test key: test_api_key
    • secret: call secret, test secret: (no need to fill in)
    • cache: [yes, no] the default is yes, the cached data will be called, and the speed is relatively fast
    • result_type: [json,xml,serialize,var_export] return data format, the default is json
    • lang:[cn,en,ru] translation language, default cn Simplified Chinese
    • secret: key
  • API:item_search parameter description:

    • q: search keywords
    • cat: Category ID
    • start_price: start price
    • end_price: end price
    • sort: Sort [bid, bid, bid2, _bid2, _sale, _credit]
      (bid: total price, bid2: commodity price, sale: sales volume, credit credit, prefixed
      to sort from large to small)
    • page: number of pages
    • page_size: the number of treasures per page, the default is 40
    • seller_info: Whether to obtain business information [yes, no], the default is yes
  • API: item_get parameter description: num_iid: baby ID

item_get-Get Taobao product details

taobao.item_get

public parameter

request parameters

Request parameters: num_iid=652874751412&is_promotion=1

Parameter description: num_iid: Taobao product ID
is_promotion: whether to get the promotion price

response parameter

Version: Date:2022-04-04

name type must example value describe

item

item[] 1 baby details data

request example

Curl


PHP

<?php

// 请求示例 url 默认请求参数已经URL编码处理
// 本示例代码未加密secret参数明文传输,若要加密请参考:https://open.…….cn/help/demo/sdk/demo-sign.php
$method = "GET";
$url = "https://api-gw.…….cn/taobao/item_get/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=652874751412&is_promotion=1";
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
var_dump(curl_exec($curl));
?>


PHPsdk

<?php
//定义缓存目录和引入文件
define("DIR_RUNTIME","runtime/");
define("DIR_ERROR","runtime/");
define("SECACHE_SIZE","0");
//SDK下载地址 https://open.…….cn/help/demo/sdk/……api-sdk.zip
include ("ObApiClient.php");

$obapi = new otao\ObApiClient();
$obapi->api_url = "http://api-gw.…….cn/";
$obapi->api_urls = array("http://api-gw.…….cn/","http://api-1.…….cn/");//备用API服务器
$obapi->api_urls_on = true;//当网络错误时,是否启用备用API服务器
$obapi->api_key = "<您自己的apiKey>";
$obapi->api_secret = "<您自己的apiSecret>";
$obapi->api_version ="";
$obapi->secache_path ="runtime/";
$obapi->secache_time ="86400";
$obapi->cache = true;

$api_data = $obapi->exec(
                array(
	                "api_type" =>"taobao",
	                "api_name" =>"item_get",
	                "api_params"=>array (
  'num_iid' => '652874751412',
  'is_promotion' => '1',
)
                )
            );
 var_dump($api_data);
?>


JAVA

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.PrintWriter;
import java.net.URLConnection;

public class Example {
	private static String readAll(Reader rd) throws IOException {
		StringBuilder sb = new StringBuilder();
		int cp;
		while ((cp = rd.read()) != -1) {
			sb.append((char) cp);
		}
		return  sb.toString();
	}
	public static JSONObject postRequestFromUrl(String url, String body) throws IOException, JSONException {
		URL realUrl = new URL(url);
		URLConnection conn = realUrl.openConnection();
		conn.setDoOutput(true);
		conn.setDoInput(true);
		PrintWriter out = new PrintWriter(conn.getOutputStream());
		out.print(body);
		out.flush();
		InputStream instream = conn.getInputStream();
		try {
			BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));
			String jsonText = readAll(rd);
			JSONObject json = new JSONObject(jsonText);
			return json;
		} finally {
			instream.close();
		}
	}
	public static JSONObject getRequestFromUrl(String url) throws IOException, JSONException {
		URL realUrl = new URL(url);
		URLConnection conn = realUrl.openConnection();
		InputStream instream = conn.getInputStream();
		try {
			BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));
			String jsonText = readAll(rd);
			JSONObject json = new JSONObject(jsonText);
			return json;
		} finally {
			instream.close();
		}
	}
	public static void main(String[] args) throws IOException, JSONException {
		// 请求示例 url 默认请求参数已经URL编码处理
		String url = "https://api-gw.o&.cn/taobao/item_get/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=652874751412&is_promotion=1";
		JSONObject json = getRequestFromUrl(url);
		System.out.println(json.toString());
	}

}


C#
Python
Golang
javascript
JS-SDK
Ruby
Swift
Objective-C
C
C++
Node.JS
Kotlin
Rust
R
MATLAB
 

Guess you like

Origin blog.csdn.net/onebound_linda/article/details/130881324