Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Gostaria de saber como faço para enviar por POST os parametros necessários e capturar o retorno com PHP.
Tentei utilizar a classe abaixo, mas não obtive o retorno.
Somente white-screen-of-death
o display_errors do meu php.ini esta ativado.
a url da documentação da api é
http://developers.mercadolibre.com/authentication-and-authorization/#!/php
O code eu consegui obter o retorno, pois pode ser pego via GET,
mas o access_token não.
Agradeço qualquer ajuda.
<?php
/**
* Classe para envio de dados via post
* @author Lucas Nishimura
*/
class Post2Url {
private $url = "";
private $cUrl;
private $reponse = "";
private $timeout = 5;
private $params = array();
function __construct($url) {
$this->setUrl ( $url );
$this->initCurl();
}
public function getTimeout() {
return $this->timeout;
}
public function setTimeout($timeout) {
$this->timeout = $timeout;
}
private function initCurl() {
$this->setCUrl ( curl_init () );
curl_setopt ( $this->getCUrl (), CURLOPT_URL, $this->getUrl () );
curl_setopt ( $this->getCUrl (), CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $this->getCUrl (), CURLOPT_CONNECTTIMEOUT, $this->getTimeout () );
}
public function getParams() {
return $this->params;
}
public function addParam($paramName,$ParamValue){
$this->params[$paramName] = $ParamValue;
}
public function sendData(){
curl_setopt($this->getCUrl(), CURLOPT_POSTFIELDS, $this->params);
return curl_exec($this->getCUrl());
}
public function getCUrl() {
return $this->cUrl;
}
public function getReponse() {
return $this->reponse;
}
public function getUrl() {
return $this->url;
}
public function setCUrl($cUrl) {
$this->cUrl = $cUrl;
}
public function setReponse($reponse) {
$this->reponse = $reponse;
}
public function setUrl($url) {
$this->url = $url;
}
}
//Variáveis API Mercado Livre.
$clientId = 'appId';
$clientSecret = 'Secret';
$code = 'code' ;
$appCallBackUrl = 'http://myurl/callback';
//Include da classe
require_once 'Post2Url.php';
//Instância um novo objeto
$teste = new Post2Url("https://api.mercadolibre.com/oauth/token?grant_type=&client_id=&client_secret=&code=&redirect_uri=");
$teste->addParam("grant_type","authorization_code");
$teste->addParam("client_id",$clientId);
$teste->addParam("client_secret",$clientSecret);
$teste->addParam("code",$code);
$teste->addParam("redirect_uri",$appCallBackUrl);
//Adiciona o parâmetro pass com valor teste
//Envia os dados xD
print_r($teste->sendData());
?>Carregando comentários...