这是我第一次使用Facebook凭证登录。我希望能够通过我的帐户查询Airbnb中的列表。我在Airbnb的原始账号是通过Facebook登录的。以下是airbnb页面上的示例请求:http://airbnbapi.org/#login-by-facebook。
我不确定在哪里可以得到我的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()发布于 2017-03-30 19:56:36
我遇到了和你一样的问题。我终于想通了。我使用的工具是requests库的高级函数,即Session(),用于保存cookie。登录与第三方帐户的重要部分是找到链接,我们需要张贴的cookies。以下是我的代码。
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.https://stackoverflow.com/questions/38643564
复制相似问题