1

What's the alternative of doing this, in Python?

  curl -X POST \
         -H 'accept: application/json' \
         -H 'content-type: application/x-www-form-urlencoded' \
         'https://api.mercadolibre.com/oauth/token' \
         -d 'grant_type=client_credentials' \
         -d 'client_id=CLIENT_ID' \
         -d 'client_secret=CLIENT_SECRET'

And the JSON response is something like this:

Status code: 200 OK
{
    "access_token": "TU_ACCESS_TOKEN",
    "token_type": "bearer",
    "expires_in": 10800,
    "scope": "...",
    "refresh_token": "REFRESH_TOKEN"
}

Anyone knows how can I get the access_token? Not the entire JSON, I only need the access_token.

Thanks

1
  • Why not parse the JSON to a dictionary then get the token by key? Commented Jul 30, 2014 at 13:15

3 Answers 3

2

There appears to be a Python library for MercadoLibre which wraps all that up for you.

Sign up to request clarification or add additional context in comments.

Comments

1

Something like this should work for you:

import httplib
import urllib

conn = httplib.HTTPSConnection("api.mercadolibre.com")
conn.request("POST", "/oauth/token", urllib.urlencode({
    "grant_type": "client_credentials",
    "client_id": "CLIENT_ID",
    "client_secret": "CLIENT_SECRET",
  }), {"accept": "application/json", "content-type": "application/x-www-form-urlencoded"})
conn.getresponse()

Comments

1

Look here http://docs.python-requests.org/en/latest/ requests library is good enough.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.