1. Go to this page and download the library: Download wandesnet/mercado-livre 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/ */
wandesnet / mercado-livre example snippets
final class Meli extends MeliConnector
{
public ?int $tries = 2; // default 1, try to request api 2 times if fail
public function resolveBaseUrl(): string
{
return 'https://api.mercadolibre.com';
}
protected function defaultOauthConfig(): OAuthConfig
{
return OAuthConfig::make()
->setClientId('3232321')
->setClientSecret('fs4343fs423')
->setAuthorizeEndpoint('https://auth.mercadolivre.com.br/authorization')
->setRedirectUri('http://my-site.com/callback.php')
->setTokenEndpoint('oauth/token');
}
protected function refreshTokenExpireIn(): void
{
if ($this->hasExpired()) {
$refresh = $this->refreshAccessToken($this->refresh_token);
$this->access_token = $refresh->getAccessToken();
$this->refresh_token = $refresh->getRefreshToken();
$this->expires_in = $refresh->getExpiresAt()->getTimestamp();
}
}
}