Skip to content

Instantly share code, notes, and snippets.

@pablomoretti
Created April 19, 2014 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pablomoretti/a9a0add16dbbe0ee2f49 to your computer and use it in GitHub Desktop.
Save pablomoretti/a9a0add16dbbe0ee2f49 to your computer and use it in GitHub Desktop.
MercadoLibre get access token client credentials example
<?php
$CURL_OPTS = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 60
);
$CLIENT_ID = "XXXXXXXXX";
$CLIENT_SECRET = "XXXXXXXXX";
function get_access_token(){
$body = array(
"grant_type" => "client_credentials",
"client_id" => $GLOBALS['CLIENT_ID'],
"client_secret" => $GLOBALS['CLIENT_SECRET'],
);
$opts = array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body
);
$ch = curl_init('https://api.mercadolibre.com/oauth/token');
curl_setopt_array($ch, $GLOBALS['CURL_OPTS']);
curl_setopt_array($ch, $opts);
$response = json_decode(curl_exec($ch),TRUE);
curl_close($ch);
return $response['access_token'];
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment