How to get real estate data with Idealista API?
<p>I've been trying to use the API of the website Idealista (<a href="https://www.idealista.com/" rel="nofollow">https://www.idealista.com/</a>) to retrieve information of real estate data. </p>

<p>Since I'm not familiarized with OAuth2 I haven't been able to obtain the token so far. I have just been provided with the api key, the secret and some basic info of how to mount the http request. </p>

<p>I would appreciate an example (preferably in Python) of the functioning of this API, or else some more generic info about dealing with OAuth2 and Python.</p>

<p>After some days of research I came up with a basic python code to retrieve real estate data from the Idealista API.</p>

<pre><code>def get_oauth_token():
http_obj = Http()
url = "https://api.idealista.com/oauth/token"
apikey= urllib.parse.quote_plus('Provided_API_key')
secret= urllib.parse.quote_plus('Provided_API_secret')
auth = base64.encode(apikey + ':' + secret)
body = {'grant_type':'client_credentials'}
headers = {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8','Authorization' : 'Basic ' + auth}
resp, content = http_obj.request(url,method='POST',headers=headers, body=urllib.parse.urlencode(body))
return content
</code></pre>

<p>This function would return a JSON with the OAuth2 token and the session time in seconds. Afterwards, to query the API, it would be as simple as:</p>

<pre><code>def search_api(token):
http_obj = Http()
url = "http://api.idealista.com/3.5/es/search?center=40.42938099999995,-3.7097526269835726&amp;country=es&amp;maxItems=50&amp;numPage=1&amp;distance=452&amp;propertyType=bedrooms&amp;operation=rent"
headers = {'Authorization' : 'Bearer ' + token}
resp, content = http_obj.request(url,method='POST',headers=headers)
return content
</code></pre>

<p>This time the we would find in the content var the data we were looking for, again as a JSON. </p>

python oauth2