• 0
Sign in to follow this  
Federico Diaz Bobillo

authentication and refresh token flow

Question

5 answers to this question

Recommended Posts

  • 0

Please check that your Redirect URI is the same as the one that you are using on your code (http://applications.mercadolibre.com/)

Also check your AppId and Secret

 

Go to: http://developers.mercadolibre.com/first-step/ under the section  Give it a try with your App! e nter the application ID you've just created and click on Show Information

 

on Your code:

Check this lines on your SDK example_login.php you must have the same URL that you config on the Redirect URI

 

$meli->authorize($_GET['code'], 'http://YOUR_URL/php-sdk/examples/example_login.php');

 

$meli->getAuthUrl('http://YOUR_URL/php-sdk/examples/example_login.php')

Share this post


Link to post
Share on other sites
  • 0

Login works well, but when you run refresh token returns error 400. These are the code and the error.

	require 'MercadoLivre/meli.php';
	$verif_user = mysql_query("SELECT * FROM authentication_users WHERE user_id = $user_id_callback");
	$oAuth = mysql_fetch_object($verif_user);
	$meli = new Meli($conf['APP_ID'], $conf['SECRET_KEY'], $oAuth->access_token, $oAuth->refresh_token);
		if(mysql_num_rows($verif_user) > 0) {
		// Verifica la data de expires del token y hace el refresh_token
		if($oAuth->expires_in < time()) {
			try {
				// Make the refresh proccess
				$refresh = $meli->refreshAccessToken();
				echo "<h1>REFRESH ACCESS TOKEN</h1>";
				var_dump($refresh);
				// Now we create the sessions with the new parameters
				if($refresh['body']->access_token) {
					mysql_query("UPDATE authentication_users SET access_token = '{$refresh['body']->access_token}', refresh_token = '{$refresh['body']->refresh_token}', expires_in =  ".(time() + $refresh['body']->expires_in)." WHERE user_id = $cust_id");
				} else {
					// aca puedes hacer el oauth novamente
					print "Error refresh";
				}
			} catch (Exception $e) {
				echo "Exception: ",  $e->getMessage(), "\n";
			}
		} else {
			print "<center>AUTENTICADO</center>";
			$user = $meli->get('users/me?access_token='.$oAuth->access_token);
		}
	
	}

Error: array(2) { ["body"]=> object(stdClass)#3 (4) { ["message"]=> string(103) "Error validating grant. Your authorization code or refresh token may be expired or it was already used." ["error"]=> string(13) "invalid_grant" ["status"]=> int(400) ["cause"]=> array(0) { } } ["httpCode"]=> int(400) } Error refresh

Share this post


Link to post
Share on other sites
  • 0

Hola, estoy teniendo problemas para autorizarme desde mi aplicación. Hace unos días estaba funcionando. Hay algún problema para loguearse desde la api?

El error que me tira es "{\"message\":\"Error validating grant. Your authorization code or refresh token may be expired or it was already used.\",\"error\":\"invalid_grant\",\"status\":400,\"cause\":[]}"

Tengo configurado correctamente el redirecUuri en la app.

Estoy usando el sdk .net y este error me sale ANTES de la autenticación, sale al ejecutar el método 'authorize', con lo cual no estoy usando ni accesstoken ni el refreshtoken en esta etapa.

Leyendo la documentación, dice que cuando sale este error tengo que hacer un nuevo request para obtener un nuevo código o refresh token, pero al tratar nuevamente de autorizar, meli me devuelve el mismo código que antes.

Probé con 3 cuentas que tengo en mercado libre y con las 3 me tira el mismo error.

 

Que estoy haciendo mal ???

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this