I make a request in php-curl and some data is lost in the response. (The data array is filled with empty objects, data is lost here)
My code is :
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.vimeo.com/albums/5694909/videos?page=1&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass=',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Connection: keep-alive',
'Accept: application/vnd.vimeo.video;version=3.4.1',
'Origin: https://vimeo.com',
'Authorization: jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2Mzk0NzQ0NDAsInVzZXJfaWQiOjE1OTc1Nzk3NSwiYXBwX2lkIjo1ODQ3OSwic2NvcGVzIjoicHVibGljIHN0YXRzIHByaXZhdGUiLCJ0ZWFtX3VzZXJfaWQiOm51bGx9.6y_6aX_jChvbHpzK_72Y5SiHHrur44EEu1jh-1PZfn0',
'Sec-Fetch-Dest: empty',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
'Content-Type: application/json',
'Sec-Fetch-Site: same-site',
'Sec-Fetch-Mode: cors',
'Referer: https://vimeo.com/showcase/5694909?page=1',
'Accept-Language: en-US,en;q=0.9'
),
));
$response = curl_exec($curl);
print_r(curl_getinfo($curl));
curl_close($curl);
echo $response;
Here is the output :
curl_getinfo
Array (
[url] => https://api.vimeo.com/albums/5694909/videos?page=1&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass=
[content_type] => application/vnd.vimeo.video+json
[http_code] => 200
[header_size] => 1036
[request_size] => 1096
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.875052
[namelookup_time] => 0.000937
[connect_time] => 0.060644
[pretransfer_time] => 0.380411
[size_upload] => 0
[size_download] => 1401
[speed_download] => 1601
[speed_upload] => 0
[download_content_length] => 1401
[upload_content_length] => 0
[starttransfer_time] => 0.875005
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 151.101.64.217
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 192.168.1.9
[local_port] => 59793
[http_version] => 2
[protocol] => 2
[ssl_verifyresult] => 0
[scheme] => HTTPS
[appconnect_time_us] => 380306
[connect_time_us] => 60644
[namelookup_time_us] => 937
[pretransfer_time_us] => 380411
[redirect_time_us] => 0
[starttransfer_time_us] => 875005
[total_time_us] => 875052 )
response :
{
"total": 76,
"page": 1,
"per_page": 12,
"paging": {
"next": "/albums/5694909/videos?page=2&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass=",
"previous": null,
"first": "/albums/5694909/videos?page=1&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass=",
"last": "/albums/5694909/videos?page=7&sort=manual&fields=description%252Cduration%252Cis_free%252Clive%252Cname%252Cpictures.sizes.link%252Cpictures.sizes.width%252Cpictures.uri%252Cprivacy.download%252Cprivacy.view%252Ctype%252Curi%252Cuser.link%252Cuser.name%252Cuser.pictures.sizes.link%252Cuser.pictures.sizes.width%252Cuser.uri&per_page=12&filter=&_hashed_pass="
},
"data": [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
] }
Please note the empty arrays in "data" key at the end.
I tried the same request in postman and jQuery. It returns correct data without any loss. Javascript attached below.
var settings = {
"url": "https://api.vimeo.com/albums/5694909/videos?page=1&sort=manual&fields=description%2Cduration%2Cis_free%2Clive%2Cname%2Cpictures.sizes.link%2Cpictures.sizes.width%2Cpictures.uri%2Cprivacy.download%2Cprivacy.view%2Ctype%2Curi%2Cuser.link%2Cuser.name%2Cuser.pictures.sizes.link%2Cuser.pictures.sizes.width%2Cuser.uri&per_page=12&filter=&_hashed_pass=",
"method": "GET",
"timeout": 0,
"headers": {
"Connection": "keep-alive",
"Accept": "application/vnd.vimeo.video;version=3.4.1",
"Origin": "https://vimeo.com",
"Authorization": "jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2Mzk0NzQ0NDAsInVzZXJfaWQiOjE1OTc1Nzk3NSwiYXBwX2lkIjo1ODQ3OSwic2NvcGVzIjoicHVibGljIHN0YXRzIHByaXZhdGUiLCJ0ZWFtX3VzZXJfaWQiOm51bGx9.6y_6aX_jChvbHpzK_72Y5SiHHrur44EEu1jh-1PZfn0",
"Sec-Fetch-Dest": "empty",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36",
"Content-Type": "application/json",
"Sec-Fetch-Site": "same-site",
"Sec-Fetch-Mode": "cors",
"Referer": "https://vimeo.com/showcase/5694909?page=1",
"Accept-Language": "en-US,en;q=0.9"
},
};
$.ajax(settings).done(function (response) {
document.write("data key contains :");
document.write(JSON.stringify(response['data']));
});</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Why does php lose some of the data (the data key arrays) and how can I retain it?
Your CURLOPT_URL is wrong. It should be:
CURLOPT_URL => 'https://api.vimeo.com/albums/5694909/videos?page=1&sort=manual&fields=description%2Cduration%2Cis_free%2Clive%2Cname%2Cpictures.sizes.link%2Cpictures.sizes.width%2Cpictures.uri%2Cprivacy.download%2Cprivacy.view%2Ctype%2Curi%2Cuser.link%2Cuser.name%2Cuser.pictures.sizes.link%2Cuser.pictures.sizes.width%2Cuser.uri&per_page=12&filter=&_hashed_pass=',
You probably url-encoded twice.