Issue
I'm trying to connect to Airbnb and return my reservations from it. I was able to successfully login using cURL, but I can't retrieve the reservations.
The reservations URL: http://airbnbapi.org/#get-host-messages
As you can see the HTTP Method is GET
, client_id
must be passed in the URL and X-Airbnb-OAuth-Token
in the headers (after login).
After perform the cURL on login I receive the following header output (by using the function CURLINFO_HEADER_OUT
):
POST /v1/authorize HTTP/1.1
Host: api.airbnb.com
Accept: */*
Content-Length: 511
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------aa1ew132ff32wca9
With the 200 HTTP code.
After login, I perform the cURL on reservations and I get:
GET /v2/threads?client_id=MyApiKey&_limit=10 HTTP/1.1
Host: api.airbnb.com
Accept: */*
{"error_code":404,"error_type":"invalid_action","error_message":"Action not found."}
With the following code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.airbnb.com/v2/threads?client_id=MyApiKey&_limit=10');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Airbnb-OAuth-Token: ' . $MyAccessToken));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$response = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerout = curl_getinfo($ch, CURLINFO_HEADER_OUT);
curl_close($ch);
print_r($headerout);
return array($http, $response);
If I use the hurl.it with my values it works without any problem.
Solution
Solved.
The problem was that my return
should be decoding the $response
as JSON and instead I'm retrieving it as plain text and therefore I'm not able to get the access_token
parameter.
And since error_reporting
is turned off, I didn't see that access_token
was empty.
return array($http, json_decode($response));
Answered By - Linesofcode