Skip to content

Instantly share code, notes, and snippets.

@rodurma
Created March 15, 2012 17:11
Show Gist options
  • Save rodurma/2045346 to your computer and use it in GitHub Desktop.
Save rodurma/2045346 to your computer and use it in GitHub Desktop.
API Mercado Libre - Reply
<?php
session_start();
require 'meli-php/src/meli.php';
$meli = new Meli(array(
'appId' => 'appId',
'secret' => 'secret'
));
$userId = $meli->initConnect();
if ($userId) {
$user = $meli->getWithAccessToken('/users/me');
if (isset($_GET['ac'])){
if ($_GET['ac'] == 'responder'){
$ar_resposta = array(
'question_id' => $_POST['id_pergunta'],
'text' => $_POST['resposta']
);
$retorno = $meli->postWithAccessToken('/answers', $ar_resposta);
echo "<pre>";
print_r($retorno);
echo "</pre>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<?php if ($userId): ?>
<p>Hello <?php echo $user['first_name'] ?> </p>
<p><a href="index.php?ac=perguntas-pendentes">Questions</a></p>
<?
if (isset($_GET['ac'])){
if ($_GET['ac'] == 'perguntas-pendentes'){
//=15563465&status=UNANSWERED
$ar_perguntas = array(
'seller' => $user['id'],
'status' => 'UNANSWERED'
);
$perguntas = $meli->getWithAccessToken('/questions/search', $ar_perguntas);
foreach($perguntas['questions'] as $pergunta){
?>
<h3><?=$pergunta['text']?></h3>
<p>
<a href="http://www.mercadolivre.com.br/jm/item?site=<?=substr($pergunta['item_id'],0,3)?>&id=<?=str_replace("MLB", "", $pergunta['item_id'])?>">Produto</a> -
Data: <?=date("d/m/Y H:i:s", strtotime($pergunta['date_created']))?>
<form action="index.php?ac=responder" method="POST">
<input type="hidden" name="id_pergunta" value="<?=$pergunta['id']?>" />
<textarea name="resposta" cols="50" rows="3"></textarea><br />
<input type="submit" value="Responder" />
</form>
</p>
<hr />
<?
}
}
}
?>
<a href="<?php echo $meli->getLogoutUrl(); ?>">Logout</a>
<?php else: ?>
<div>
<p> Login using OAuth 2.0 handled by the PHP SDK: </p>
<a href="<?php echo $meli->getLoginUrl(); ?>">Login with MercadoLibre</a>
</div>
<?php endif ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment