1. Go to this page and download the library: Download ecomphp/lazada-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ecomphp / lazada-php example snippets
use EcomPHP\Lazada\Client;
$app_key = 'your_app_key_here';
$app_secret = 'your_app_secret_here';
$callback_url = 'https://your-app.com/lazada/callback';
$client = new Client($app_key, $app_secret, $callback_url);
$auth = $client->auth();
$state = 'your-csrf-or-tracking-state';
$country = 'vn'; // Optional: vn, sg, my, th, ph, id
// Returns the Lazada authentication URL instead of auto-redirecting
$authUrl = $auth->createAuthRequest($state, $country, true);
// Redirect user to Lazada Authorization page
header('Location: ' . $authUrl);
exit;
$authorization_code = $_GET['code'];
// Exchange code for Access Token & Refresh Token
$token = $auth->getToken($authorization_code);
$access_token = $token['access_token'];
$refresh_token = $token['refresh_token'];
// IMPORTANT: Save your access_token, refresh_token, and seller region to your database for later use