php Taobao Web Query Commodity Interface Code Example

  • 2021-06-29 10:36:03
  • OfStack

This article will introduce you to an example of the php version of Taobao website to query the commodity interface code. The next step is to change your information to be explained at the end of the code. We also want to officially download the sdk package.

After downloading SDK, refer directly to the package, create the following classes, and run them, completing the process of invoking the interface (taobao.user.seller.get) (the invocation interface description shows the downloaded SDK)
Explain:
TopClient is an instantiated class that calls SDK
UserSellerGetRequest encapsulates a class for API's request parameters

Note: This interface is called in a sandbox environment, and the data obtained is also the data in the sandbox.To get an online environment, fill in the appkey, appsecret that you got from creating your own application, change the environment address of the calling interface, and modify nick to be the landing name of Taobao.

Download the SDK package and place it in the same directory as the file.

<?php
header("Content-type: text/html; charset=utf-8");
include "TopSdk.php";
// Will Download SDK After decompression top In TopClient.php No. 8 That's ok $gatewayUrl Change value to sandbox address :http://gw.api.tbsandbox.com/router/rest,
// This address needs to be set to when in a formal environment :http://gw.api.taobao.com/router/rest

// instantiation TopClient class 
$c = new TopClient;
$c->appkey = "xxxxxx"; // Replace with yours appkey
$c->secretKey = "xxxxxxxx"; // Replace with yours secretKey
$sessionkey= "xxxxxx";   // Such as sandbox test account number sandbox_c_1 Authorized sessionkey
// Instantiate concrete API Corresponding Request class 
$req = new UserSellerGetRequest;
$req->setFields("nick,user_id,type");
//$req->setNick("sandbox_c_1");

// implement API Request and print results 
$resp = $c->execute($req,$sessionkey);
echo "result:";
print_r($resp);
?>


Related articles: