Error 403 when getting data from Airbnb API

泪湿孤枕 提交于 2021-02-11 05:57:47

问题


I am trying to pull data from the Airbnb API, but I get a HTTP 403 error when running my code, this means I somehow don't have access to the Airbnb server. However, I do have an API key. Can someone please help me out here? Help is very much appreciated!

This is my code:

#Import required modules
import amadeus
import urllib2
import json

client_id= "**********"


#URL
URL = "https://api.airbnb.com/v2/search_results?  client_id=***********otqw18e8nh5nty&locale=en-US&currency=USD&_format=for_search_results_with_minimal_pricing&_limit=10&_offset=0&fetch_facets=true&guests=1&ib=false&ib_add_photo_flow=true&location=Lake%20Tahoe%2C%20CA%2C%20US&min_bathrooms=0&min_bedrooms=0&min_beds=1&min_num_pic_urls=10&price_max=210&price_min=40&sort=1&user_lat=37.3398634&user_lng=-122.0455164"
print URL

#Convert to Json format
json_obj = urllib2.urlopen(URL)

data = json.load(json_obj)

print data

回答1:


you have to send your apikey in request like this:

import urllib2
request = urllib2.Request("yourURL", headers={"X-Airbnb-OAuth-Token" : "yourapikey"})
contents = urllib2.urlopen(request).read()

(im not 100% sure, but maybe it helps)




回答2:


remove the spaces between '?' and 'client_id=...'

When I do that and then do a curl call, I get results.

And: never post your API-Key on sites like this.



来源:https://stackoverflow.com/questions/40178477/error-403-when-getting-data-from-airbnb-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!