2016-07-28 540 views
1

这是我第一次使用Facebook凭证登录。我希望能够通过我的账户查询Airbnb中的房源。我在Airbnb的原始帐户是通过Facebook登录。以下是airbnb页面上的示例请求:http://airbnbapi.org/#login-by-facebook使用Airbnb登录或API登录

我不知道在哪里可以得到我的client_id和Facebook的访问令牌。虽然它指向https://developers.facebook.com/docs/facebook-login/access-tokens以获取用户访问令牌,但如果我理解正确,它需要我创建一个应用程序。我不确定我需要使用哪种认证流程才能使用Airbnb API。

我已经看过Airbnb文档来搜索client_id,但没用。

这是我到目前为止有:

import requests 
import json 

API_URL = "https://api.airbnb.com" 
LISTING_ENDPOINT= "https://api.airbnb.com/v2/search_results" 

post_query = { 
    "client_id": "I HAVE NO IDEA WHERE TO GET IT", 
    "locale": "en-US", 
    "currency":"USD", 
    "assertion_type":"https://graph.facebook.com/me" 
    "assertion":"HOW SHOULD I GET THIS ONE?", 
    "prevent_account_creation":True 
} 

# I think this should be able to log me in and I should be able to query listings 
_ = requests.post(API_URL, post_query).json() 

query = { 
    "client_id":"FROM ABOVE", 
    "user_lat": "40.00", 
    "user_long":"-54.31" 
} 


listings = requests.get(LISTING_ENDPOINT, json=query).json() 
+0

似乎没有公开的API,但访问私有的似乎微不足道 –

+0

我如何得到我的客户端ID? – mousecoder

回答

1

我碰到了同样的问题来了,你。我终于明白了。我使用的工具是请求库的高级功能,即Session(),用于保存Cookie。使用第三方帐户登录的重要部分是找到我们需要发布Cookie的链接。以下是我的代码。

import requests 
x=requests.Session() #savig the cookies when you click the "log in with facebook button" 
y=requests.Session() #saving the cookies for parsing the airbnb listing. 
account={'email':'your_facebook_account','pass':'your_facebook_ps'} 
log_in_with_facebook_click=x.post("https://www.airbnb.jp/oauth_connect?from=facebook_login&service=facebook") 

#all the cookies up to now is saved in "x" 
my_first_time_cookies=x.cookies.get_dict() 
real_login_link=log_in_with_facebook_click.url 

real_log_in=y.post(real_login_link,account,cookies=my_first_time_cookies) 
#the real login link is saved in "log_in_with_facebook" 
#pass the cookies and your facebook account information to the real login link 
#you should have logged into airbnb.For testing the log in, we do the following. We check the reservation data. 

from bs4 import BeautifulSoup 
page=1 
test=y.get("https://www.airbnb.jp/my_reservations?page="+str(page)) 
#Remember that the cookies we use to access airbnb website after loggin in is saved in "y" 
test_html=BeautifulSoup(test.text,'lxml') 
print(test_html.text) 
#you should have looked your tenants reservation information.