0

Is there a way to programmatically login to Airbnb with email/password through a CLI PHP script? and get a response back?

Thanks.

Vincent
  • 3
  • 2
  • 1
    Does Airbnb have an API you're trying to use? Or are you just trying to log in without one? I'm a little confused on what you're trying to do... – Tim Aug 20 '15 at 21:01
  • Airbnb does not have an API. so a workaround i am thinking is using a web crawler to try and do the same with a script. basically the script will run open the airbnb login page enter the email/password into the form submit it and return the result. there are crawlers that allow form submission. I tried on the Airbnb site and was not successful. – Vincent Aug 21 '15 at 00:20

2 Answers2

0

If you're looking to remotely log in to Airbnb and return information, you can use cURL to post data to Airbnb and return the results.

Examples on how to post form data can be found all over the web, however, a very reputable tutorial can be found here. Essentially, you want to cURL the login page, and include the login information with POST.

<?php
// A very simple PHP example that sends a HTTP POST to a remote site

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://www.airbnb.com/login");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "email=" . $email . "&password=" . $password);

// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('email' => $email, 'password' => $password)));

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

// further processing ....
if ($server_output == "OK") { ... } else { ... }
?>

Make sure you check out this answer on SO, as well as the tutorials here.

Community
  • 1
  • 1
Tim
  • 2,002
  • 4
  • 23
  • 37
0

Yes, there is. Airbnb's API isn't open to the general public, but if you sniff the traffic from your phone, you can see what requests are being sent to which endpoints. I experimented a little bit with their API and it follows as such for logging in

<?php
class AirBnB {    
// Define the properties
public $currency = 'USD';
public $language = 'en';
public $country = 'us';
public $network = 'AT&T';
public $apiKey = '915pw2pnf4h1aiguhph5gc5b2';
public $adId = '911EBF1C-7C1D-46D5-A925-2F49ED064C92';
public $deviceId = 'a382581f36f1635a78f3d688bf0f99d85ec7e21f';

public function SendRequest($endpoint, $token, $post, $data, $cookies) {
    $headers = array(
                'Host: api.airbnb.com',
                'Accept: application/json',
                'Accept-Language: en-us',
                'Connection: keep-alive',
                'Content-Type: application/json',
                'Proxy-Connection: keep-alive',
                'X-Airbnb-Carrier-Country: '.$this->country,
                'X-Airbnb-Currency: '.$this->currency,
                'X-Airbnb-Locale: '.$this->language,
                'X-Airbnb-Carrier-Name: '.$this->network,
                'X-Airbnb-Network-Type: wifi',
                'X-Airbnb-API-Key: '.$this->apiKey,
                'X-Airbnb-Device-ID: '.$this->deviceId,
                'X-Airbnb-Advertising-ID: '.$this->adId,
                );

    // Add the new custom headers
    if($token) {
        $header = 'X-Airbnb-OAuth-Token: '.$token;
        array_push($headers, $header);
    }

    // Add the query string
    if(!$post && is_array($data)) {
        $endpoint .= '?'.http_build_query($data);
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.airbnb.com/'.$endpoint);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Airbnb/15.50 iPhone/9.2 Type/Phone');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    if($post) {
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    }

    if($cookies) {
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');            
    } else {
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
    }

    $response = curl_exec($ch);
    $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);    

    return array(
                'http' => $http,
                'response' => $response
                );
}

public function Authorize($username, $password) {
    $data = array(
                'username' => $username,
                'password' => $password,
                'prevent_account_creation' => TRUE,
                );
    $data = $this->SendRequest('v1/authorize', FALSE, TRUE, $data, FALSE);

    if($data['http'] == 200) {
        $json = @json_decode($data['response'], TRUE);
        return $json['access_token'];
    } else {
        return FALSE;
    }
}
}

// Call a new instance of AirBnB
$airbnb = new AirBnB;

// Get the OAuth token
$token = $airbnb->Authorize('my@email.com', 'password');
?>

You can find out more about their API here.

Lance
  • 4,488
  • 16
  • 49
  • 85
  • 1
    Hello Lance, your script is very interesting and working very well, I was just wondering one thing : about the variables `$apiKey`, `$adId` and `$deviceId` : is that OK if everyone who use your class have the same values ? If not, where to get other values ? Do we have to capture the traffic from our own mobile app ? Also, what other endpoints have you come accross ? Thank you in advance – M. Kejji Jun 24 '16 at 15:19
  • @lance This script is not working for me in CLI (using PHP) ? IS there any changes in this code ? – HaRsH Nov 25 '17 at 12:20