首页 > 解决方案 > 通过 CURL 登录 Airbnb

问题描述

我正在尝试对 Airbnb 进行 API 调用,但您必须登录才能进行这些调用,并且没有公共 API,我只能尝试提出解决方案。

我首先尝试通过 CURL 登录,我正在尝试使用这段代码,但我运气不佳。

$url = "https://www.airbnb.co.uk/login";
$postinfo = "email=".$username."&password=".$password;

$cookie_file_path = $path."/cookie.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
//for certain features, set the cookie the site has - this is optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
    "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, $url);
$html_data = curl_exec($ch);
curl_close($ch);
echo $html_data;

我得到的回应是:

{
success: false,
redirect: ""
}

我哪里出错了(我已经声明了变量、用户名和密码,但显然已经忽略了)。

标签: phpcurl

解决方案


您无法通过 curl 登录 Airbnb,因为 Airbnb 使用无法解析的谷歌验证码。这就是它返回的原因success: false

如果你想对他们的应用做点什么,你应该尝试去这里申请成为合作伙伴,以便使用他们的 API。


推荐阅读