New question

Question:

Date: 30-09-2019 08:57:45 (In Spanish)

Conectar con Mercado Libre[Unresolved]

Saludos, estoy iniciando con el api de mercado libre y estoy teniendo problemas para conectarme, tengo este codigo:

<?php
// Try to put this code at the top (attention to the path)
require 'Meli/meli.php';
// Create our Application instance (replace this with your appId and secret).
$meli = new Meli("xxxxxxxxx", "xxxxxxxxxxx");
if($_GET['code']):
  $oAuth = $meli->authorize($_GET['code'], 'https://somoskiwi.net/admin/prueba_login.php');
  $_SESSION['access_token'] = $oAuth['body']->access_token;
else:
  echo 'Login with MercadoLibre';
endif;
?>


Ahora, qué tengo que poner en el enlace para hacer la dirección hacia mercado libre para que el usuario se loguee?

Gracias.
Tags: API - Mercadolibre API - PHP - Question - Web Votes: 0 - Answers: 3 - Views: 15 Share on: Google Facebook Twitter LinkedIn Link
 

Answers:

  • Date: 01-10-2019 07:32:09
    
    <?php
    session_start();
    require '../Meli/meli.php';
    require '../configApp.php';
    $meli = new Meli($appId, $secretKey);
    if(isset($_GET['code']) || isset($_SESSION['access_token'])) {
    	// If code exist and session is empty
    	if(isset($_GET['code']) && !isset($_SESSION['access_token'])) {
    		// //If the code was in get parameter we authorize
    		try{
    			$user = $meli->authorize($_GET["code"], $redirectURI);
    			
    			// Now we create the sessions with the authenticated user
    			$_SESSION['access_token'] = $user['body']->access_token;
    			$_SESSION['expires_in'] = time() + $user['body']->expires_in;
    			$_SESSION['refresh_token'] = $user['body']->refresh_token;
    		}catch(Exception $e){
    			echo "Exception: ",  $e->getMessage(), "\n";
    		}
    	} else {
    		// We can check if the access token in invalid checking the time
    		if($_SESSION['expires_in'] < time()) {
    			try {
    				// Make the refresh proccess
    				$refresh = $meli->refreshAccessToken();
    				// Now we create the sessions with the new parameters
    				$_SESSION['access_token'] = $refresh['body']->access_token;
    				$_SESSION['expires_in'] = time() + $refresh['body']->expires_in;
    				$_SESSION['refresh_token'] = $refresh['body']->refresh_token;
    			} catch (Exception $e) {
    			  	echo "Exception: ",  $e->getMessage(), "\n";
    			}
    		}
    	}
    	echo '<pre>';
    		print_r($_SESSION);
    	echo '</pre>';
    } else {
    	echo '<a href="' . $meli->getAuthUrl($redirectURI, Meli::$AUTH_URL[$siteId]) . '">Login using MercadoLibre oAuth 2.0</a>';
    }
    
      Votes: 1 - Link answer
     
  • Date: 01-10-2019 20:21:41 @Andy Martinez, me sale un error, la pagina con el mensaje "Estamos trabajando.."   Votes: 0 - Link answer
     
  • Date: 03-10-2019 10:52:16 disculpa cual pagina, si es la de la api comunicarte con los de mercado libre talves te disponga de otra ruta   Votes: 0 - Link answer
     
To actively participate in the community first must authenticate, enter the system.Sign In
 
frjcbbae garagebible.com