2016-07-28 4 views
1

Facebook 자격 증명을 사용하여 로그인하는 것을 처음으로 처리합니다. 내 계정을 통해 Airbnb의 목록을 쿼리 할 수 ​​있기를 원합니다. Airbnb의 원래 계정은 Facebook 로그인입니다. 다음은 airbnb 페이지의 샘플 요청입니다 : http://airbnbapi.org/#login-by-facebook.Facebook 로그인으로 Airbnb API 사용

내 client_id 및 Facebook의 액세스 토큰을 어디서 얻을 수 있는지 잘 모르겠습니다. 사용자 액세스 토큰을 얻으려면 https://developers.facebook.com/docs/facebook-login/access-tokens을 가리 키지 만 올바르게 이해하면 앱을 만들어야합니다. Airbnb API를 사용하려면 어떤 인증 흐름이 필요한지 잘 모르겠습니다.

나는 이미 Airbnb docs에서 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())의 고급 기능입니다. 타사 계정으로 로그인 할 때 중요한 부분은 쿠키를 게시하는 데 필요한 링크를 찾는 것입니다. 다음은 내 코드입니다.

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. 
관련 문제