• 0
Sign in to follow this  
juan

Problema con autenticación

Question

Buenos dias , estoy arrancando a programar con la api de meli con la sdk de java y estoy teniendo problemas para loguearme adjunto parte del codigo:

Meli m = new Meli( ID, "CLAVE");
m.authorize("the received code", "http://somecallbackurl");

FluentStringsMap params = new FluentStringsMap();
params.add("access_token", m.getAccessToken());
Response response = m.get("/users/me", params);

Reemplazo ID por mi app id ,  la clave por el secret key de mi app y la direccion http://somecallbackurlpor la seteada en mi app por de todos modos ahi no entiendo bien si tiene que ser alguna direccion especifica o cualquiera.

 

Al correr la app el error que me devuelve es el siguiente : Exception in thread "main" com.mercadolibre.sdk.AuthorizationFailure: Error validating grant. Your authorization code or refresh token may be expired or it was already used.

 

Por lo que puedo entender no me esta devolviendo el codigo , nose que estoy haciendo mal

Espero respuesta , recomendaciones ejemplos , lo que sea para poder proseguir con el desarrollo , desde ya muchas gracias !

 

 

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hello,

 

the line with variables : m.authorize("the received code", "http://somecallbackurl");

You must use the data received and your page address to process, example:

m.authorize($_GET("code"), "http://www.hypefoodtruck.mx/ml/auth.jsp");

 

$_GET("code") is the function to get variable passed in PHP, wher $_GET() is the function and "code" is the variable´s name

 

I believe that works. 

Rodrigo

Share this post


Link to post
Share on other sites
  • 0

coloca isso que vai funcionar!

 

    public static $CURL_OPTS = array(
        CURLOPT_USERAGENT => "MELI-PHP-SDK-1.0.0",
        CURLOPT_SSLVERSION => 1,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_TIMEOUT => 60,
    );

Share this post


Link to post
Share on other sites
  • 0

Hi! i'll write on english to avoid the languaje problems heheeh

 

I'm having the same problem using de java-sdk

 

My loging process is the next code.

At first:

 @RequestMapping("/login")
    public ModelAndView login() {
        String authUrl = meli.getAuthUrl("http://localhost:8081/meli/autorization", AuthUrls.MLA);

        return new ModelAndView("redirect:" + authUrl);
    }

Redirect actions goes to:

@RequestMapping("/autorization")
    public ModelAndView autorization(WebRequest webRequest) {
        if(!requestHasErrors(webRequest)){
            try {
                meli.authorize(webRequest.getParameter("code"),"http://localhost:8081/meli/summary");
            } catch (AuthorizationFailure authorizationFailure) {
                log.error("Unexpected Error for MELI authentication");
            }
        }
        return new ModelAndView();
    }

and finally:

@RequestMapping("/summary")
    public ModelAndView summary(WebRequest webRequest ) {
        requestHasErrors(webRequest);

        return new ModelAndView();
    }

I'm receiving the next Exception on authorize() method

Exception: AuthorizationFailure

Cause: ar.com.gilwell.interactions.meli.sdk.AuthorizationFailure: Error validating grant. Your authorization code or refresh token may be expired or it was already used.

DetailedMessage: Error validating grant. Your authorization code or refresh token may be expired or it was already used.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this